res_partner.py 930 B

1234567891011121314151617181920212223242526
  1. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  2. from odoo import fields, api, models
  3. class ResPartner(models.Model):
  4. _inherit = "res.partner"
  5. branch_code = fields.Char("Branch Code", default='000', compute='_compute_branch_code', store=True)
  6. first_name = fields.Char("First Name")
  7. middle_name = fields.Char("Middle Name")
  8. last_name = fields.Char("Last Name")
  9. @api.model
  10. def _commercial_fields(self):
  11. return super()._commercial_fields() + ['branch_code']
  12. @api.depends('vat', 'country_id')
  13. def _compute_branch_code(self):
  14. for partner in self:
  15. branch_code = '000'
  16. if partner.country_id.code == 'PH' and partner.vat:
  17. match = partner.__check_vat_ph_re.match(partner.vat)
  18. branch_code = match and match.group(1) and match.group(1)[1:] or branch_code
  19. partner.branch_code = branch_code