mirror of
https://github.com/bringout/oca-ocb-l10n_americas.git
synced 2026-04-27 08:52:06 +02:00
19.0 vanilla
This commit is contained in:
parent
89c6e82fe7
commit
1b82c20a58
572 changed files with 43570 additions and 53303 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue