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.

71 lines
2.9 KiB

5 years ago
5 years ago
  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. sub_reqs = coop.subscription_request_ids.filtered(lambda r: r.state in ['done', 'paid'])
  36. if sub_reqs:
  37. sub_req = sub_reqs[0]
  38. if self.legal_form:
  39. coop_vals['legal_form'] = sub_req.company_type
  40. coop.write(coop_vals)
  41. if self.representative_function:
  42. contact = coop.get_representative()
  43. contact.function = sub_req.contact_person_function
  44. else:
  45. coops = partner_obj.search([('cooperator', '=', True),
  46. ('birthdate_date', '=', False),
  47. ('is_company', '=', False)])
  48. for coop in coops:
  49. coop_vals = {}
  50. sub_reqs = coop.subscription_request_ids.filtered(lambda r: r.state in ['done', 'paid'])
  51. if sub_reqs:
  52. sub_req = sub_reqs[0]
  53. if self.birthdate:
  54. coop_vals['birthdate_date'] = sub_req.birthdate
  55. coop.write(coop_vals)
  56. else:
  57. if cooperator:
  58. if cooperator.is_company:
  59. coop_vals['company_register_number'] = self.register_number
  60. if coop_vals:
  61. cooperator.write(coop_vals)
  62. return True