| 1 |
|
| 2 |
|
| 3 |
from odoo import models, _ |
| 4 |
|
| 5 |
|
| 6 |
SG_TAX_CATEGORIES = {'SR', 'SRCA-S', 'SRCA-C', 'SROVR-RS', 'SRRC', 'SROVR-LVG', 'SRLVG', 'ZR', 'ES33', 'ESN33', 'DS', 'OS', 'NG', 'NA'} |
| 7 |
SG_GST_CODES_REQUIRING_ADDRESS = {'SR', 'SRCA-S', 'SRCA-C', 'ZR', 'SRRC', 'SROVR-RS', 'SROVR-LVG', 'SRLVG', 'NA'} |
| 8 |
|
| 9 |
|
| 10 |
class AccountEdiXmlPint_Sg(models.AbstractModel): |
| 11 |
_name = 'account.edi.xml.pint_sg' |
| 12 |
_inherit = ["account.edi.xml.ubl_bis3"] |
| 13 |
_description = "Singapore implementation of Peppol International (PINT) model for Billing" |
| 14 |
""" |
| 15 |
Pint is a standard for International Billing from Peppol. It is based on Peppol BIS Billing 3. |
| 16 |
It serves as a base for per-country specialization, while keeping a standard core for data being used |
| 17 |
across countries. This is not meant to be used directly, but rather to be extended by country-specific modules. |
| 18 |
|
| 19 |
The SG PINT format is the Singapore implementation of PINT. |
| 20 |
|
| 21 |
* PINT Official documentation: https://docs.peppol.eu/poac/pint/pint/ |
| 22 |
* PINT SG Official documentation: https://docs.peppol.eu/poac/sg/2024-Q2/pint-sg/ |
| 23 |
""" |
| 24 |
|
| 25 |
def _export_invoice_filename(self, invoice): |
| 26 |
|
| 27 |
return f"{invoice.name.replace('/', '_')}_pint_sg.xml" |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
def _get_customization_id(self, process_type='billing'): |
| 34 |
if process_type == 'billing': |
| 35 |
return 'urn:peppol:pint:billing-1@sg-1' |
| 36 |
|
| 37 |
def _ubl_default_tax_category_grouping_key(self, base_line, tax_data, vals, currency): |
| 38 |
|
| 39 |
grouping_key = super()._ubl_default_tax_category_grouping_key(base_line, tax_data, vals, currency) |
| 40 |
if not grouping_key: |
| 41 |
return |
| 42 |
|
| 43 |
grouping_key['scheme_id'] = 'GST' |
| 44 |
return grouping_key |
| 45 |
|
| 46 |
def _add_invoice_header_nodes(self, document_node, vals): |
| 47 |
|
| 48 |
super()._add_invoice_header_nodes(document_node, vals) |
| 49 |
invoice = vals['invoice'] |
| 50 |
|
| 51 |
|
| 52 |
document_node['cbc:ProfileID'] = {'_text': 'urn:peppol:bis:billing'} |
| 53 |
document_node['cbc:UUID'] = {'_text': invoice._l10n_sg_get_uuid()} |
| 54 |
|
| 55 |
if invoice.currency_id != invoice.company_id.currency_id: |
| 56 |
amounts_in_accounting_currency = ( |
| 57 |
('sgdtotal-excl-gst', invoice.amount_untaxed_signed), |
| 58 |
('sgdtotal-incl-gst', invoice.amount_total_signed), |
| 59 |
) |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
document_node['cac:AdditionalDocumentReference'] = [ |
| 64 |
{ |
| 65 |
'cbc:ID': {'_text': invoice.company_id.currency_id.name}, |
| 66 |
'cbc:DocumentTypeCode': {'_text': code}, |
| 67 |
'cbc:DocumentDescription': {'_text': amount}, |
| 68 |
} |
| 69 |
for code, amount in amounts_in_accounting_currency |
| 70 |
] |
| 71 |
|
| 72 |
def _get_party_node(self, vals): |
| 73 |
party_node = super()._get_party_node(vals) |
| 74 |
party_node['cac:PartyTaxScheme'][0]['cac:TaxScheme']['cbc:ID']['_text'] = 'GST' |
| 75 |
return party_node |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
def _export_invoice_constraints(self, invoice, vals): |
| 82 |
|
| 83 |
constraints = super()._export_invoice_constraints(invoice, vals) |
| 84 |
|
| 85 |
|
| 86 |
for tax_total_node in vals['document_node']['cac:TaxTotal']: |
| 87 |
for tax_subtotal_node in tax_total_node['cac:TaxSubtotal']: |
| 88 |
for tax_category_node in tax_subtotal_node['cac:TaxCategory']: |
| 89 |
if tax_category_node['cbc:ID']['_text'] not in SG_TAX_CATEGORIES: |
| 90 |
constraints['sg_vat_category_required'] = _("You must set a Singaporean tax category on each taxes of the invoice.") |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
if tax_category_node['cbc:ID']['_text'] in SG_GST_CODES_REQUIRING_ADDRESS: |
| 96 |
constraints['sg_seller_street_addr_required'] = \ |
| 97 |
self._check_required_fields(vals['supplier'], 'street') |
| 98 |
constraints['sg_seller_post_code_required'] = \ |
| 99 |
self._check_required_fields(vals['supplier'], 'zip') |
| 100 |
|
| 101 |
return constraints |