Skip to content

Commit

Permalink
[FIX] l10n_it_edi: do not mingle downpayment lines in negative lines …
Browse files Browse the repository at this point in the history
…dispath

The downpayment moves need to be reported in the FatturaCollegate and
also as real negative lines in the XML.

That worked in 16, but as we added the dispatch of the negative lines
on the line discounts of the positive lines, the negative downpayment
linked line got swallowed by the dispatch.  The fix is to not dispatch
downpayment linked lines.

opw-4274292

closes odoo#186755

Signed-off-by: Wala Gauthier (gawa) <[email protected]>
  • Loading branch information
jco-odoo committed Nov 12, 2024
1 parent bb40cf9 commit ae69eab
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions addons/l10n_it_edi/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,18 @@ def _l10n_it_edi_get_line_values(self, reverse_charge_refund=False, is_downpayme
template = self.env['ir.qweb']._load('l10n_it_edi.account_invoice_line_it_FatturaPA')[0]
flat_discount_element = template.find('.//ScontoMaggiorazione/Percentuale')
if flat_discount_element is not None:
downpayment_lines = []
if not is_downpayment:
# Negative lines linked to down payment should stay negative
for line_dict in base_lines:
line = line_dict['record']
if line.price_subtotal < 0 and line._get_downpayment_lines():
downpayment_lines.append(line_dict)
base_lines.remove(line_dict)
dispatch_result = self.env['account.tax']._dispatch_negative_lines(base_lines)
base_lines = sorted(
dispatch_result['result_lines'] + dispatch_result['orphan_negative_lines'] + dispatch_result['nulled_candidate_lines'],
dispatch_result['result_lines'] + dispatch_result['orphan_negative_lines'] + dispatch_result['nulled_candidate_lines']
+ downpayment_lines,
key=itemgetter('sequence')
)
else:
Expand All @@ -291,10 +300,10 @@ def _l10n_it_edi_get_line_values(self, reverse_charge_refund=False, is_downpayme
'line': line,
'line_number': num + 1,
'description': description or 'NO NAME',
'subtotal_price_eur': (line_dict['gross_price_subtotal'] - line_dict['discount_amount']) * inverse_factor,
'subtotal_price': (line_dict['gross_price_subtotal'] - line_dict['discount_amount']) * inverse_factor * line_dict['rate'],
'subtotal_price_eur': (line_dict['gross_price_subtotal'] - line_dict.get('discount_amount', 0.0)) * inverse_factor,
'subtotal_price': (line_dict['gross_price_subtotal'] - line_dict.get('discount_amount', 0.0)) * inverse_factor * line_dict['rate'],
'unit_price': line_dict['price_unit'],
'discount_amount': ((line_dict['discount_amount'] - line_dict['discount_amount_before_dispatching']) / line.quantity) if line.quantity else 0,
'discount_amount': ((line_dict.get('discount_amount', 0.0) - line_dict['discount_amount_before_dispatching']) / line.quantity) if line.quantity else 0,
'vat_tax': line.tax_ids.flatten_taxes_hierarchy().filtered(lambda t: t._l10n_it_filter_kind('vat') and t.amount >= 0),
'downpayment_moves': downpayment_moves,
'discount_type': (
Expand Down

0 comments on commit ae69eab

Please sign in to comment.