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.

72 lines
2.9 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. req_filter = "lambda r: r.type == 'done'"
  30. if self.all:
  31. if self.legal_form or self.representative_function:
  32. coops = partner_obj.search([('cooperator', '=', True),
  33. ('is_company', '=', True)])
  34. for coop in coops:
  35. coop_vals = {}
  36. sub_reqs = coop.subscription_request_ids.filtered(req_filter)
  37. if sub_reqs:
  38. sub_req = sub_reqs
  39. if self.legal_form:
  40. coop_vals['legal_form'] = sub_req.company_type
  41. coop.write(coop_vals)
  42. if self.representative_function:
  43. contact = coop.get_representative()
  44. contact.function = sub_req.contact_person_function
  45. else:
  46. coops = partner_obj.search([('cooperator', '=', True),
  47. ('birthdate_date', '=', False),
  48. ('is_company', '=', False)])
  49. for coop in coops:
  50. coop_vals = {}
  51. sub_reqs = coop.subscription_request_ids.filtered(req_filter)
  52. if sub_reqs:
  53. sub_req = sub_reqs
  54. if self.birthdate:
  55. coop_vals['birthdate_date'] = sub_req.birthdate
  56. coop.write(coop_vals)
  57. else:
  58. if cooperator:
  59. if cooperator.is_company:
  60. coop_vals['company_register_number'] = self.register_number
  61. if coop_vals:
  62. cooperator.write(coop_vals)
  63. return True