19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:31:16 +01:00
parent 89c6e82fe7
commit 1b82c20a58
572 changed files with 43570 additions and 53303 deletions

View file

@ -1,7 +1,9 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import template_pe
from . import account_tax
from . import account_move
from . import l10n_latam_identification_type
from . import res_bank
from . import res_partner
from . import res_city_district
from . import res_city

View file

@ -1,6 +1,5 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, models, fields
from odoo.tools.sql import column_exists, create_column
from odoo import api, models
class AccountMove(models.Model):
@ -9,19 +8,30 @@ class AccountMove(models.Model):
def _get_l10n_latam_documents_domain(self):
self.ensure_one()
result = super()._get_l10n_latam_documents_domain()
if self.company_id.country_id.code != "PE" or not self.journal_id.l10n_latam_use_documents:
if self.company_id.country_id.code != "PE" or not self.l10n_latam_use_documents or self.journal_id.type != "sale":
return result
if self.journal_id.type == "sale":
result.append(("code", "in", ("01", "03", "07", "08", "20", "40")))
result.append(("code", "in", ("01", "03", "07", "08", "20", "40")))
if self.partner_id.l10n_latam_identification_type_id.l10n_pe_vat_code != '6' and self.move_type == 'out_invoice':
result.append(('id', 'in', (
self.env.ref('l10n_pe.document_type08b')
| self.env.ref('l10n_pe.document_type02')
| self.env.ref('l10n_pe.document_type07b')
).ids))
return result
@api.onchange('l10n_latam_document_type_id', 'l10n_latam_document_number', 'partner_id')
def _inverse_l10n_latam_document_number(self):
"""Inherit to complete the l10n_latam_document_number with the expected 8 characters after that a '-'
Example: Change FFF-32 by FFF-00000032, to avoid incorrect values on the reports"""
After formatting the document number with zfill(8), the name field is also synchronized
to ensure both fields remain consistent.
Example: Change F01-32 by F01-00000032, to avoid incorrect values on the reports
"""
super()._inverse_l10n_latam_document_number()
to_review = self.filtered(
lambda x: x.journal_id.type == "purchase"
and x.l10n_latam_document_type_id
and x.l10n_latam_document_type_id.code in ("01", "03", "07", "08")
and x.l10n_latam_document_number
and "-" in x.l10n_latam_document_number
@ -31,22 +41,11 @@ class AccountMove(models.Model):
number = rec.l10n_latam_document_number.split("-")
rec.l10n_latam_document_number = "%s-%s" % (number[0], number[1].zfill(8))
class AccountMoveLine(models.Model):
_inherit = "account.move.line"
l10n_pe_group_id = fields.Many2one("account.group", related="account_id.group_id", store=True)
def _auto_init(self):
"""
Create column to stop ORM from computing it himself (too slow)
"""
if not column_exists(self.env.cr, self._table, 'l10n_pe_group_id'):
create_column(self.env.cr, self._table, 'l10n_pe_group_id', 'int4')
self.env.cr.execute("""
UPDATE account_move_line line
SET l10n_pe_group_id = account.group_id
FROM account_account account
WHERE account.id = line.account_id
""")
return super()._auto_init()
# Synchronize the name field with the formatted document number
# to ensure consistency between l10n_latam_document_number and name fields
expected_name = (
f"{rec.l10n_latam_document_type_id.doc_code_prefix} "
f"{rec.l10n_latam_document_number}"
)
if rec.name != expected_name:
rec.name = expected_name

View file

@ -5,26 +5,33 @@ from odoo import fields, models
class AccountTax(models.Model):
_inherit = "account.tax"
l10n_pe_edi_tax_code = fields.Selection([
('1000', 'IGV - General Sales Tax'),
('1016', 'IVAP - Tax on Sale Paddy Rice'),
('2000', 'ISC - Selective Excise Tax'),
('7152', 'ICBPER - Plastic bag tax'),
('9995', 'EXP - Exportation'),
('9996', 'GRA - Free'),
('9997', 'EXO - Exonerated'),
('9998', 'INA - Unaffected'),
('9999', 'OTROS - Other taxes')
], 'EDI peruvian code')
l10n_pe_edi_tax_code = fields.Selection(
[
('1000', 'IGV - General Sales Tax'),
('1016', 'IVAP - Tax on Sale Paddy Rice'),
('2000', 'ISC - Selective Excise Tax'),
('7152', 'ICBPER - Plastic bag tax'),
('9995', 'EXP - Exportation'),
('9996', 'GRA - Free'),
('9997', 'EXO - Exonerated'),
('9998', 'INA - Unaffected'),
('9999', 'OTHERS - Other taxes')
],
string='Code',
help="Peru: SUNAT tax code",
)
l10n_pe_edi_unece_category = fields.Selection([
('E', 'Exempt from tax'),
('G', 'Free export item, tax not charged'),
('O', 'Services outside scope of tax'),
('S', 'Standard rate'),
('Z', 'Zero rated goods')], 'EDI UNECE code',
help="Follow the UN/ECE 5305 standard from the United Nations Economic Commission for Europe for more "
"information http://www.unece.org/trade/untdid/d08a/tred/tred5305.htm"
l10n_pe_edi_unece_category = fields.Selection(
[
('E', 'Exempt from tax'),
('G', 'Free export item, tax not charged'),
('O', 'Services outside scope of tax'),
('S', 'Standard rate'),
('Z', 'Zero rated goods')
],
string='UNECE Code',
help="Peru: Follow the UN/ECE 5305 standard from the United Nations Economic Commission for Europe for more "
"information http://www.unece.org/trade/untdid/d08a/tred/tred5305.html"
)
l10n_pe_edi_isc_type = fields.Selection([
('01', 'System to value'),
@ -32,44 +39,3 @@ class AccountTax(models.Model):
('03', 'Retail Price System'),
], 'ISC Type',
help='Used in Selective Consumption Tax to indicate the type of calculation for the ISC.')
class AccountTaxTemplate(models.Model):
_inherit = "account.tax.template"
l10n_pe_edi_tax_code = fields.Selection([
('1000', 'IGV - General Sales Tax'),
('1016', 'IVAP - Tax on Sale Paddy Rice'),
('2000', 'ISC - Selective Excise Tax'),
('7152', 'ICBPER - Plastic bag tax'),
('9995', 'EXP - Exportation'),
('9996', 'GRA - Free'),
('9997', 'EXO - Exonerated'),
('9998', 'INA - Unaffected'),
('9999', 'OTROS - Other taxes')
], 'EDI peruvian code')
l10n_pe_edi_unece_category = fields.Selection([
('E', 'Exempt from tax'),
('G', 'Free export item, tax not charged'),
('O', 'Services outside scope of tax'),
('S', 'Standard rate'),
('Z', 'Zero rated goods')], 'EDI UNECE code',
help="Follow the UN/ECE 5305 standard from the United Nations Economic Commission for Europe for more "
"information http://www.unece.org/trade/untdid/d08a/tred/tred5305.htm"
)
l10n_pe_edi_isc_type = fields.Selection([
('01', 'System to value'),
('02', 'Application of the Fixed Amount'),
('03', 'Retail Price System'),
], 'ISC Type',
help='Used in Selective Consumption Tax to indicate the type of calculation for the ISC.')
def _get_tax_vals(self, company, tax_template_to_tax):
val = super()._get_tax_vals(company, tax_template_to_tax)
val.update({
'l10n_pe_edi_tax_code': self.l10n_pe_edi_tax_code,
'l10n_pe_edi_unece_category': self.l10n_pe_edi_unece_category,
'l10n_pe_edi_isc_type': self.l10n_pe_edi_isc_type,
})
return val

View file

@ -2,8 +2,7 @@
from odoo import models, fields
class L10nLatamIdentificationType(models.Model):
class L10n_LatamIdentificationType(models.Model):
_inherit = "l10n_latam.identification.type"
l10n_pe_vat_code = fields.Char()

View file

@ -0,0 +1,9 @@
from odoo import fields, models
class ResBank(models.Model):
_inherit = 'res.bank'
l10n_pe_edi_code = fields.Char(
'Code (PE)',
help='Bank code assigned by the SUNAT to identify banking institutions.')

View file

@ -2,7 +2,7 @@
from odoo import fields, models
class City(models.Model):
class ResCity(models.Model):
_inherit = "res.city"
l10n_pe_code = fields.Char('Code', help='This code will help with the '

View file

@ -2,7 +2,7 @@
from odoo import fields, models
class L10nPeResCityDistrict(models.Model):
class L10n_PeResCityDistrict(models.Model):
_name = 'l10n_pe.res.city.district'
_description = 'District'
_order = 'name'

View file

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models
@ -9,4 +9,7 @@ class ResCompany(models.Model):
def _localization_use_documents(self):
# OVERRIDE
self.ensure_one()
return self.account_fiscal_country_id.code == "PE" or super()._localization_use_documents()
return self.chart_template == 'pe' or self.account_fiscal_country_id.code == "PE" or super()._localization_use_documents()
def _is_latam(self):
return super()._is_latam() or self.country_code == 'PE'

View file

@ -24,3 +24,9 @@ class ResPartner(models.Model):
def _formatting_address_fields(self):
"""Returns the list of address fields usable to format addresses."""
return super()._formatting_address_fields() + ['l10n_pe_district_name']
def _get_frontend_writable_fields(self):
frontend_writable_fields = super()._get_frontend_writable_fields()
frontend_writable_fields.update({'city_id', 'l10n_pe_district'})
return frontend_writable_fields

View file

@ -0,0 +1,47 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models
from odoo.addons.account.models.chart_template import template
class AccountChartTemplate(models.AbstractModel):
_inherit = 'account.chart.template'
@template('pe')
def _get_pe_template_data(self):
return {
'property_account_receivable_id': 'chart1213',
'property_account_payable_id': 'chart4212',
'property_stock_valuation_account_id': 'chart20111',
'code_digits': '7',
}
@template('pe', 'res.company')
def _get_pe_res_company(self):
return {
self.env.company.id: {
'account_fiscal_country_id': 'base.pe',
'bank_account_code_prefix': '1041',
'cash_account_code_prefix': '1031',
'transfer_account_code_prefix': '1051',
'account_default_pos_receivable_account_id': 'chart1215',
'income_currency_exchange_account_id': 'chart776',
'expense_currency_exchange_account_id': 'chart676',
'account_journal_early_pay_discount_loss_account_id': 'chart675',
'account_journal_early_pay_discount_gain_account_id': 'chart775',
'account_sale_tax_id': 'sale_tax_igv_18',
'account_purchase_tax_id': 'purchase_tax_igv_18',
'expense_account_id': 'chart6329',
'income_account_id': 'chart70121',
'account_stock_journal_id': 'inventory_valuation',
'account_stock_valuation_id': 'chart20111',
},
}
@template('pe', 'account.account')
def _get_pe_account_account(self):
return {
'chart20111': {
'account_stock_expense_id': 'chart6111',
'account_stock_variation_id': 'chart69121',
},
}