Skip to content

Commit

Permalink
Merge branch '16.0' into 17.0-mig-001-jl
Browse files Browse the repository at this point in the history
  • Loading branch information
jose-pcg committed May 16, 2024
2 parents 9b6c5b5 + a8c9881 commit 6b33048
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 2 deletions.
4 changes: 3 additions & 1 deletion l10n_do_accounting/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ def _get_l10n_do_amounts(self):
"""
self.ensure_one()

return self.line_ids._get_l10n_do_line_amounts()
return self.line_ids.filtered(
lambda line: line.currency_id == self.currency_id
)._get_l10n_do_line_amounts()

@api.depends(
"company_id",
Expand Down
26 changes: 25 additions & 1 deletion l10n_do_accounting/models/monkey_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,31 @@ class AccountMove(models.Model):
"posted_before", "state", "journal_id", "date", "move_type", "payment_id"
)
def _compute_name(self):
super(AccountMove, self)._compute_name()
self = self.sorted(lambda m: (m.date, m.ref or "", m._origin.id))

for move in self:
if move.state == "cancel":
continue

move_has_name = move.name and move.name != "/"
if move_has_name or move.state != "posted":
if not move.posted_before and not move._sequence_matches_date():
if move._get_last_sequence():
move.name = False
continue
else:
if (
move_has_name
and move.posted_before
or not move_has_name
and move._get_last_sequence()
):
continue
if move.date and (not move_has_name or not move._sequence_matches_date()):
move._set_next_sequence()

self.filtered(lambda m: not m.name and not move.quick_edit_mode).name = "/"
self._inverse_name()

for move in self.filtered(
lambda x: x.country_code == "DO"
Expand Down
11 changes: 11 additions & 0 deletions l10n_do_accounting/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ def setUpClass(cls, chart_template_ref="l10n_do.do_chart_template"):
street="dummy address",
country_id=cls.env.ref("base.do").id,
)["company"]

# multi-currency variables
cls.usd_currency = cls.env.ref("base.USD")
cls.env["res.currency.rate"].create(
{
"currency_id": cls.usd_currency.id,
"rate": 0.01694915254,
"company_id": cls.do_company.id,
}
)

cls.fiscal_partner = cls.env["res.partner"].create(
{
"name": "ITERATIVO SRL",
Expand Down
92 changes: 92 additions & 0 deletions l10n_do_accounting/tests/test_account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,3 +711,95 @@ def test_010_ncf_format(self):

with self.assertRaises(ValidationError):
self._create_l10n_do_invoice(data={"document_number": "B310000000001"})

def test_011_get_l10n_do_line_amounts(self):
invoice_1 = self._create_l10n_do_invoice(
data={
"document_number": "B0100000001",
}
)
self.assertDictEqual(
invoice_1._get_l10n_do_amounts(),
{
"base_amount": 100.0,
"exempt_amount": 0,
"isr_withholding_amount": 0,
"isr_withholding_base_amount": 0,
"itbis_0_base_amount": 0,
"itbis_0_tax_amount": 0,
"itbis_16_base_amount": 0,
"itbis_16_tax_amount": 0,
"itbis_18_base_amount": 100.0,
"itbis_18_tax_amount": 18.0,
"itbis_withholding_amount": 0,
"itbis_withholding_base_amount": 0,
"l10n_do_invoice_total": 118.0,
},
)

invoice_2 = self._create_l10n_do_invoice(
data={
"partner": self.consumo_partner,
"document_number": "B1100000001",
"expense_type": "02",
},
invoice_type="in_invoice",
)

self.assertDictEqual(
invoice_2._get_l10n_do_amounts(),
{
"base_amount": 100.0,
"exempt_amount": 0,
"isr_withholding_amount": 10.0,
"isr_withholding_base_amount": 100.0,
"itbis_0_base_amount": 0,
"itbis_0_tax_amount": 0,
"itbis_16_base_amount": 0,
"itbis_16_tax_amount": 0,
"itbis_18_base_amount": 100.0,
"itbis_18_tax_amount": 18.0,
"itbis_withholding_amount": 18.0,
"itbis_withholding_base_amount": 100.0,
"l10n_do_invoice_total": 118.0,
},
)

invoice_3 = self._create_l10n_do_invoice(
data={
"document_number": "B0100000002",
"currency": self.usd_currency,
}
)

self.assertDictEqual(
invoice_3._get_l10n_do_amounts(),
{
"base_amount": 100.0,
"base_amount_currency": 5900.000000825999,
"exempt_amount": 0,
"exempt_amount_currency": 0.0,
"isr_withholding_amount": 0,
"isr_withholding_amount_currency": 0.0,
"isr_withholding_base_amount": 0,
"isr_withholding_base_amount_currency": 0.0,
"itbis_0_base_amount": 0,
"itbis_0_base_amount_currency": 0.0,
"itbis_0_tax_amount": 0,
"itbis_0_tax_amount_currency": 0.0,
"itbis_16_base_amount": 0,
"itbis_16_base_amount_currency": 0.0,
"itbis_16_tax_amount": 0,
"itbis_16_tax_amount_currency": 0.0,
"itbis_18_base_amount": 100.0,
"itbis_18_base_amount_currency": 5900.000000825999,
"itbis_18_tax_amount": 18.0,
"itbis_18_tax_amount_currency": 1062.0000001486799,
"itbis_withholding_amount": 0,
"itbis_withholding_amount_currency": 0.0,
"itbis_withholding_base_amount": 0,
"itbis_withholding_base_amount_currency": 0.0,
"l10n_do_invoice_total": 118.0,
"l10n_do_invoice_total_currency": 6962.000000974679,
},
)

0 comments on commit 6b33048

Please sign in to comment.