Skip to content

Commit

Permalink
Merge PR OCA#3505 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by SirAionTech
  • Loading branch information
OCA-git-bot committed Sep 2, 2024
2 parents fe06373 + e48104b commit e687f99
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 6 deletions.
23 changes: 17 additions & 6 deletions l10n_it_reverse_charge/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ class AccountMoveLine(models.Model):
"tax_ids",
)
def _compute_rc_flag(self):
for line in self.filtered(lambda r: not r.exclude_from_invoice_tab):
if line.move_id.is_purchase_document():
line.rc = bool(line.move_id.fiscal_position_id.rc_type_id)
for line in self:
move = line.move_id
is_rc = (
move.is_purchase_document()
and move.fiscal_position_id.rc_type_id
and not line.display_type
and not line.exclude_from_invoice_tab
)
line.rc = is_rc

rc = fields.Boolean(
"RC", compute="_compute_rc_flag", store=True, readonly=False, default=False
Expand Down Expand Up @@ -127,8 +133,11 @@ def _rc_get_move_line_to_reconcile(self):
else:
raise UserError(_("Only inbound and outbound moves are supported"))

to_reconcile_move_lines = self.line_ids.filtered(
lambda ml: ml.account_id.reconcile
)
is_zero = self.currency_id.is_zero
for move_line in self.line_ids:
for move_line in to_reconcile_move_lines:
field_value = getattr(move_line, line_field)
if not is_zero(field_value) and move_line.account_internal_type in (
"receivable",
Expand Down Expand Up @@ -386,7 +395,8 @@ def generate_self_invoice(self):
)
if line_tax_ids and mapped_taxes:
rc_invoice_line["tax_ids"] = [(6, False, mapped_taxes.ids)]
rc_invoice_line["account_id"] = rc_type.transitory_account_id.id
if line.account_id:
rc_invoice_line["account_id"] = rc_type.transitory_account_id.id
rc_invoice_lines.append([0, False, rc_invoice_line])
if rc_invoice_lines:
inv_vals = self.rc_inv_vals(
Expand Down Expand Up @@ -455,7 +465,8 @@ def generate_supplier_self_invoice(self):
line_vals["tax_ids"] = [
(6, False, mapped_taxes.ids),
]
line_vals["account_id"] = rc_type.transitory_account_id.id
if inv_line.account_id:
line_vals["account_id"] = rc_type.transitory_account_id.id
invoice_line_vals.append((0, 0, line_vals))
supplier_invoice.write({"invoice_line_ids": invoice_line_vals})
self.rc_self_purchase_invoice_id = supplier_invoice.id
Expand Down
48 changes: 48 additions & 0 deletions l10n_it_reverse_charge/tests/test_rc.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,51 @@ def test_supplier_extraEU_no_outstanding_payment(self):

payments_lines = (self_purchase_payment | self_purchase_rc_payment).line_ids
self.assertTrue(all(payments_lines.mapped("reconciled")))

def test_description_lines(self):
"""A Reverse Charge Bill can be confirmed
when contains notes and sections."""
# Arrange: Create a Reverse Charge Bill with notes and sections
bill = self.create_invoice(
self.supplier_extraEU,
amounts=[100],
taxes=self.tax_0_pur,
post=False,
)
bill.invoice_line_ids = [
(
0,
0,
{
"display_type": "line_note",
"name": "Test note",
},
),
(
0,
0,
{
"display_type": "line_section",
"name": "Test section",
},
),
]

# Act
bill.action_post()

# Assert
self.assertEqual(bill.state, "posted")

def test_negative_lines(self):
"""A Reverse Charge Bill can be confirmed
when contains negative lines."""
# Arrange: Create a Reverse Charge Bill with negative lines
bill = self.create_invoice(
self.supplier_extraEU,
amounts=[100, -10],
taxes=self.tax_0_pur,
)

# Assert
self.assertEqual(bill.state, "posted")

0 comments on commit e687f99

Please sign in to comment.