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.

53 lines
1.7 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. def check_belgian_ident_id(self, register_number):
  25. if self.env['subscription.request'].check_belgian_identification_id(
  26. register_number):
  27. return True
  28. else:
  29. raise UserError(_("The national register number is not valid."))
  30. @api.multi
  31. def update(self):
  32. cooperator = self.cooperator
  33. coop_vals = {}
  34. if cooperator.is_company:
  35. coop_vals['company_register_number'] = self.register_number
  36. else:
  37. if self.check_belgian_ident_id(self.register_number):
  38. coop_vals['national_register_number'] = self.register_number
  39. if coop_vals:
  40. cooperator.write(coop_vals)
  41. return True