Skip to content

Commit 01a3d67

Browse files
committed
[FIX] l10n_uy_ux: automatically add default legends on invoices
X-original-commit: 98e2232
1 parent aaa0273 commit 01a3d67

2 files changed

Lines changed: 37 additions & 37 deletions

File tree

l10n_uy_ux/models/account_move.py

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,14 @@ def _compute_l10n_latam_document_type(self):
158158
"""
159159
uy_cn_dn_docs = self.env["account.move"]
160160
if uy_einvoices := self.filtered(
161-
lambda m: m.country_code == "UY"
162-
and m.move_type in ("out_invoice", "out_refund")
163-
and m.state == "draft"
164-
and not m.posted_before
165-
and m.journal_id.l10n_uy_edi_type == "electronic"
166-
and m.partner_id.l10n_latam_identification_type_id == self.env.ref("l10n_uy.it_rut")
161+
lambda m: (
162+
m.country_code == "UY"
163+
and m.move_type in ("out_invoice", "out_refund")
164+
and m.state == "draft"
165+
and not m.posted_before
166+
and m.journal_id.l10n_uy_edi_type == "electronic"
167+
and m.partner_id.l10n_latam_identification_type_id == self.env.ref("l10n_uy.it_rut")
168+
)
167169
):
168170
# Set debit notes
169171
if uy_debit_notes := uy_einvoices.filtered(lambda m: m.debit_origin_id):
@@ -223,9 +225,9 @@ def uy_ux_action_get_uruware_cfe(self):
223225
# 3. validation that is the same CFE
224226

225227
uy_moves = self.filtered(
226-
lambda x: x.country_code == "UY"
227-
and x.journal_id.type == "sale"
228-
and x.journal_id.l10n_uy_edi_type == "manual"
228+
lambda x: (
229+
x.country_code == "UY" and x.journal_id.type == "sale" and x.journal_id.l10n_uy_edi_type == "manual"
230+
)
229231
)
230232
uy_docs = self.env["l10n_latam.document.type"].search([("country_id.code", "=", "UY")])
231233

@@ -304,9 +306,7 @@ def _compute_l10n_latam_document_number(self):
304306

305307
def _l10n_uy_edi_get_line_nom_and_desc(self, aml):
306308
"""
307-
Sobrescribimos este método que devuelve el valor de NomItem y DscItem para cada línea del comprobante,
308-
para utilizar siempre la descripción de la línea (aml.name) como está en Odoo nativo, ya que a veces se quiere
309-
modificar el valor a mostrar en la factura manteniendo el producto en la línea.
309+
Sobrescribimos este método que devuelve el valor de NomItem y DscItem para cada línea del comprobante...
310310
"""
311311
# B7 NomItem, B8 DscItem
312312
nom_item = aml.name and aml.name[:80] or "-"
@@ -388,20 +388,26 @@ def uy_ux_action_validate_cfe(self):
388388
raise UserError(self.env._("XML Valido"))
389389

390390
def action_l10n_uy_remkark_default(self):
391-
"""Revisamos leyedas que correspondan aplicar segun las condiciones de leyenda y defaults y las agregamos a
392-
la factura con un boton"""
391+
"""Revisamos leyendas que correspondan aplicar segun las condiciones de leyenda y defaults y las agregamos a
392+
la factura y a las líneas con un boton"""
393393
self.ensure_one()
394-
res = self.env["l10n_uy_edi.addenda"]
395394

396-
res |= self._uy_get_legends_recs("addenda", self)
397-
res |= self._uy_get_legends_recs("cfe_doc", self)
398-
res |= self._uy_get_legends_recs("emisor", self)
399-
res |= self._uy_get_legends_recs("receiver", self)
395+
# 1. Obtenemos las leyendas obligatorias
396+
default_legends = self.env["l10n_uy_edi.addenda"]
397+
default_legends |= self._uy_get_legends_recs("addenda", self)
398+
default_legends |= self._uy_get_legends_recs("cfe_doc", self)
399+
default_legends |= self._uy_get_legends_recs("emisor", self)
400+
default_legends |= self._uy_get_legends_recs("receiver", self)
400401

401-
for line in self.invoice_line_ids.filtered(lambda x: x.display_type == "product"):
402-
res |= self._uy_get_legends_recs("item", line)
402+
# Escribimos las leyendas en el move
403+
self.l10n_uy_edi_addenda_ids = default_legends
403404

404-
self.l10n_uy_edi_addenda_ids = res
405+
# 2. Obtenemos y aplicamos las leyendas de tipo "item" a cada línea
406+
for line in self.invoice_line_ids.filtered(lambda x: x.display_type == "product"):
407+
# Obtenemos las de tipo item evaluando el contexto según la línea y según el move
408+
item_legends = self._uy_get_legends_recs("item", line)
409+
# Escribimos explícitamente en el account.move.line
410+
line.l10n_uy_edi_addenda_ids = item_legends
405411

406412
def action_l10n_uy_addenda_preview(self):
407413
"""Boton que permite previsualizar las addendas que seran aplicadas en en este comprobante"""
@@ -418,7 +424,7 @@ def uy_ux_action_mandatory_legend(self):
418424
A68_InfoAdicionalReceptor = edi_model._get_legends("receiver", self)
419425
B8_DscItem = []
420426
for line in self.invoice_line_ids.filtered(lambda x: x.display_type == "product"):
421-
value = self._l10n_uy_edi_get_line_desc(line)
427+
value = self._l10n_uy_edi_get_line_nom_and_desc(line)[1]
422428
if value:
423429
B8_DscItem.append("* line (%s) : %s" % (line.display_name, value))
424430

@@ -461,11 +467,13 @@ def _uy_ux_check_moves_use_documents(self):
461467
"""Do not let to create not invoices entries in journals that use documents"""
462468
# TODO simil to _check_moves_use_documents. integrate somehow
463469
not_invoices = self.filtered(
464-
lambda x: x.company_id.country_id.code == "UY"
465-
and x.journal_id.type in ["sale", "purchase"]
466-
and x.l10n_latam_use_documents
467-
and not x.is_invoice()
468-
and x.state == "posted"
470+
lambda x: (
471+
x.company_id.country_id.code == "UY"
472+
and x.journal_id.type in ["sale", "purchase"]
473+
and x.l10n_latam_use_documents
474+
and not x.is_invoice()
475+
and x.state == "posted"
476+
)
469477
)
470478
if not_invoices:
471479
raise ValidationError(

l10n_uy_ux/views/account_move_views.xml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,7 @@
4444
<page name="uy_dgi" string="DGI" invisible="l10n_uy_edi_journal_type != 'electronic'">
4545
<separator string="Addendas and Disclosures"/>
4646
<button name="action_l10n_uy_remkark_default" type="object" string="Get Defaults"/>
47-
<field name="l10n_uy_edi_addenda_ids">
48-
<list string="Addendas">
49-
<field name="type"/>
50-
<field name="name"/>
51-
<field name="content"/>
52-
<field name="condition" optional="hide"/>
53-
</list>
54-
</field>
55-
<span>Preview: </span>
47+
<div style="margin-top: 8px; margin-bottom: 8px;"><strong>Preview:</strong></div>
5648
<button name="action_l10n_uy_addenda_preview" type="object" string="Addendas"/>
5749
<button name="uy_ux_action_mandatory_legend" type="object" string="Info/Disclosures"/>
5850
<separator string="CFE"/>

0 commit comments

Comments
 (0)