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.

75 lines
3.1 KiB

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