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.

51 lines
1.6 KiB

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