Debian Codegraph @

addons/l10n_rs_edi/models/account_edi_xml_ubl_21_rs.py

raw
1 from odoo import models
2
3
4 class AccountEdiXmlUBL21RS(models.AbstractModel):
5 _name = "account.edi.xml.ubl.rs"
6 _inherit = 'account.edi.xml.ubl_21'
7 _description = "UBL 2.1 (RS eFaktura)"
8
9 def _get_customization_id(self, process_type='billing'):
10 return 'urn:cen.eu:en16931:2017#compliant#urn:mfin.gov.rs:srbdt:2022#conformant#urn:mfin.gov.rs:srbdtext:2022'
11
12 def _add_invoice_header_nodes(self, document_node, vals):
13 # EXTENDS 'account_edi_ubl_cii'
14 super()._add_invoice_header_nodes(document_node, vals)
15 invoice = vals['invoice']
16
17 document_node['cbc:CustomizationID'] = {'_text': self._get_customization_id()}
18
19 # Billing Reference values for Credit Note
20 if invoice.move_type == 'out_refund' and invoice.reversed_entry_id:
21 document_node['cac:BillingReference'] = {
22 'cbc:ID': {'_text': invoice.reversed_entry_id.name},
23 'cbc:IssueDate': {'_text': invoice.reversed_entry_id.invoice_date},
24 }
25
26 document_node['cac:InvoicePeriod'] = [
27 document_node.get('cac:InvoicePeriod'),
28 {
29 'cbc:DescriptionCode': {
30 '_text': '0' if invoice.move_type == 'out_refund' else invoice.l10n_rs_tax_date_obligations_code
31 },
32 }
33 ]
34
35 def _get_party_node(self, vals):
36 # EXTENDS 'account_edi_ubl_cii'
37 party_node = super()._get_party_node(vals)
38 partner = vals['partner']
39
40 vat_country, vat_number = partner._split_vat(partner.vat)
41 if vat_country.isnumeric():
42 vat_country = 'RS'
43 vat_number = partner.vat
44
45 party_node['cbc:EndpointID'] = {
46 '_text': vat_number,
47 'schemeID': '9948',
48 }
49
50 if partner.country_code == 'RS' and partner.l10n_rs_edi_public_funds:
51 party_node['cac:PartyIdentification'] = {
52 'cbc:ID': {
53 '_text': f'JBKJS: {partner.l10n_rs_edi_public_funds}',
54 },
55 }
56
57 if vat_country == 'RS' and partner._check_vat_number(vat_country, vat_number):
58 party_node['cac:PartyTaxScheme']['cbc:CompanyID'] = {'_text': vat_country + vat_number}
59
60 party_node['cac:PartyLegalEntity']['cbc:CompanyID'] = {'_text': partner.l10n_rs_edi_registration_number}
61
62 return party_node