You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.8 KiB

  1. # -*- coding: utf-8 -*-
  2. from openerp import api, fields, models
  3. class PartnerUpdateInfo(models.TransientModel):
  4. _name = "partner.update.info"
  5. _description = "Update Partner Info"
  6. @api.model
  7. def _get_partner(self):
  8. active_id = self.env.context.get('active_id')
  9. return self.env['res.partner'].browse(active_id)
  10. @api.model
  11. def _get_register_number(self):
  12. partner = self._get_partner()
  13. if partner.is_company:
  14. return partner.company_register_number
  15. register_number = fields.Char(string="Register Number",
  16. default=_get_register_number)
  17. cooperator = fields.Many2one('res.partner',
  18. string="Cooperator",
  19. default=_get_partner)
  20. all = fields.Boolean(string="Update from subscription request")
  21. birthdate = fields.Boolean(string="set missing birth date")
  22. legal_form = fields.Boolean(string="Set legal form")
  23. representative_function = fields.Boolean(string="Set function")
  24. @api.multi
  25. def update(self):
  26. partner_obj = self.env['res.partner']
  27. cooperator = self.cooperator
  28. coop_vals = {}
  29. if self.all:
  30. if self.legal_form or self.representative_function:
  31. coops = partner_obj.search([('cooperator', '=', True),
  32. ('is_company', '=', True)])
  33. for coop in coops:
  34. coop_vals = {}
  35. if coop.subscription_request_ids:
  36. sub_req = coop.subscription_request_ids[0]
  37. if self.legal_form:
  38. coop_vals['legal_form'] = sub_req.company_type
  39. coop.write(coop_vals)
  40. if self.representative_function:
  41. contact = coop.get_representative()
  42. contact.function = sub_req.contact_person_function
  43. else:
  44. coops = partner_obj.search([('cooperator', '=', True),
  45. ('birthdate_date', '=', False),
  46. ('is_company', '=', False)])
  47. for coop in coops:
  48. coop_vals = {}
  49. if coop.subscription_request_ids:
  50. sub_req = coop.subscription_request_ids[0]
  51. if self.birthdate:
  52. coop_vals['birthdate_date'] = sub_req.birthdate
  53. coop.write(coop_vals)
  54. else:
  55. if cooperator:
  56. if cooperator.is_company:
  57. coop_vals['company_register_number'] = self.register_number
  58. if coop_vals:
  59. cooperator.write(coop_vals)
  60. return True