Debian Codegraph @

addons/l10n_hr_edi/models/res_partner.py

raw
1 from odoo import models, fields, api
2 from odoo.exceptions import ValidationError
3
4 TIMEOUT = 10
5
6
7 class ResPartner(models.Model):
8 _inherit = 'res.partner'
9
10 invoice_sending_method = fields.Selection(
11 selection_add=[('mojeracun', 'by MojEracun')],
12 )
13 invoice_edi_format = fields.Selection(selection_add=[('ubl_hr', "CIUS HR")])
14 l10n_hr_personal_oib = fields.Char(string="Personal OIB")
15 l10n_hr_business_unit_code = fields.Char("Business Unit Code", default=None)
16
17 # -------------------------------------------------------------------------
18 # CONSTRAINT
19 # -------------------------------------------------------------------------
20
21 @api.constrains('invoice_edi_format', 'invoice_sending_method')
22 def _check_mojeracun_send_ubl_hr(self):
23 if self.filtered(lambda partner: partner.invoice_edi_format != 'ubl_hr' and partner.invoice_sending_method == 'mojeracun'):
24 raise ValidationError(self.env._('On MojEracun, only the Croatian UBL format is supported.'))
25
26 # -------------------------------------------------------------------------
27 # OVERRIDE AND HELPERS
28 # -------------------------------------------------------------------------
29
30 def _get_edi_builder(self, invoice_edi_format):
31 # EXTENDS 'account_edi_ubl_cii'
32 if invoice_edi_format == 'ubl_hr':
33 return self.env['account.edi.xml.ubl_hr']
34 return super()._get_edi_builder(invoice_edi_format)
35
36 def _get_ubl_cii_formats_info(self):
37 # EXTENDS 'account_edi_ubl_cii'
38 formats_info = super()._get_ubl_cii_formats_info()
39 formats_info['ubl_hr'] = {'countries': ['HR'], 'on_peppol': False}
40 return formats_info
41
42 def _get_suggested_invoice_edi_format(self):
43 # EXTENDS 'account'
44 if self.country_code == 'HR':
45 return 'ubl_hr'
46 return super()._get_suggested_invoice_edi_format()