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.

43 lines
1.2 KiB

  1. # -*- coding: utf-8 -*-
  2. from openerp import api, fields, models, _
  3. from openerp.exceptions import UserError
  4. class PartnerUpdateInfo(models.TransientModel):
  5. _name = "partner.update.info"
  6. _description = "Update Partner Info"
  7. @api.model
  8. def _get_partner(self):
  9. active_id = self.env.context.get('active_id')
  10. return self.env['res.partner'].browse(active_id)
  11. @api.model
  12. def _get_register_number(self):
  13. partner = self._get_partner()
  14. if partner.is_company:
  15. return partner.company_register_number
  16. else:
  17. return partner.national_register_number
  18. register_number = fields.Char(string="Register Number",
  19. required=True,
  20. default=_get_register_number)
  21. cooperator = fields.Many2one('res.partner',
  22. string="Cooperator",
  23. default=_get_partner)
  24. @api.multi
  25. def update(self):
  26. cooperator = self.cooperator
  27. coop_vals = {}
  28. if cooperator.is_company:
  29. coop_vals['company_register_number'] = self.register_number
  30. if coop_vals:
  31. cooperator.write(coop_vals)
  32. return True