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.

47 lines
1.5 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", required=True, default=_get_register_number)
  19. cooperator = fields.Many2one('res.partner', string="Cooperator", default=_get_partner)
  20. def check_belgian_ident_id(self, register_number):
  21. if self.env['subscription.request'].check_belgian_identification_id(register_number):
  22. return True
  23. else:
  24. raise UserError(_("The national register number is not valid."))
  25. @api.multi
  26. def update(self):
  27. cooperator = self.cooperator
  28. coop_vals = {}
  29. if cooperator.is_company:
  30. coop_vals['company_register_number'] = self.register_number
  31. else:
  32. if self.check_belgian_ident_id(self.register_number):
  33. coop_vals['national_register_number'] = self.register_number
  34. if coop_vals:
  35. cooperator.write(coop_vals)
  36. return True