Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][FIX] l10n_es_aeat_mod349: Importe original incorrecto en rectificaciones de otros periodos #3468

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions l10n_es_aeat_mod349/models/mod349.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,20 +214,18 @@ def _create_349_refund_records(self):
[
("move_line_id.move_id", "=", origin_invoice.id),
("partner_record_id.operation_key", "=", op_key),
("id", "not in", visited_details.ids),
],
order="report_id desc",
limit=1,
)
# we add all of them to visited, as we don't want to repeat
visited_details |= original_details
if original_details:
origin_amount = 0.0
if original_details and original_details not in visited_details:
# There's at least one previous 349 declaration report
report = original_details.mapped("report_id")[:1]
partner_id = original_details.mapped("partner_id")[:1]
original_details = original_details.filtered(
lambda d: d.report_id == report
)
origin_amount = sum(original_details.mapped("amount_untaxed"))
period_type = report.period_type
year = str(report.year)

Expand All @@ -240,6 +238,7 @@ def _create_349_refund_records(self):
],
order="report_id desc",
)
visited_details |= all_details_period
origin_amount = sum(all_details_period.mapped("amount_untaxed"))

# If there are intermediate periods between the original
Expand Down Expand Up @@ -269,7 +268,11 @@ def _create_349_refund_records(self):
origin_amount = (
last_refund_detail.refund_id.total_operation_amount
)

elif original_details and original_details in visited_details:
# This move corresponds to a period that has already been rectified
report = original_details.mapped("report_id")[:1]
period_type = report.period_type
year = str(report.year)
else:
# There's no previous 349 declaration report in Odoo
original_amls = move_line_obj.search(
Expand Down Expand Up @@ -299,6 +302,8 @@ def _create_349_refund_records(self):
period_type = "%sT" % int(math.ceil(int(month) / 3.0))
else:
period_type = month
# we add all of them to visited, as we don't want to repeat
visited_details |= original_details
key = (partner, op_key, period_type, year)
key_vals = data.setdefault(
key, {"original_amount": 0, "refund_details": refund_detail_obj}
Expand Down
79 changes: 77 additions & 2 deletions l10n_es_aeat_mod349/tests/test_l10n_es_aeat_mod349.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TestL10nEsAeatMod349Base(TestL10nEsAeatModBase):
"P_IVA21_IC_BC//2": (150, 0),
}

def test_model_349(self):
def test_model_349_01(self):
# Add some test data
self.customer.write(
{"vat": "BE0411905847", "country_id": self.env.ref("base.be").id}
Expand Down Expand Up @@ -152,7 +152,7 @@ def test_model_349(self):
)
self.assertEqual(a_record.total_operation_amount, 300)
# Create a substitutive presentation for 2T 2017.
# We create a refund of p1, and a new sale
# We create a refund of p1 and p2 and a new sale
self._invoice_refund(p1, "2017-04-01")
self._invoice_sale_create("2017-04-01")
model349_2t = model349_model.create(
Expand Down Expand Up @@ -210,3 +210,78 @@ def test_model_349(self):
self.env.ref("l10n_es_aeat_mod349.act_report_aeat_mod349_pdf")._render(
model349.ids
)

def test_model_349_02(self):
"""When we enter refunds in another period, the rectifications section must correctly
report the right amounts"""
# Add some test data
self.customer.write(
{"vat": "BE0411905847", "country_id": self.env.ref("base.be").id}
)
self.supplier.write(
{"vat": "BG0000100159", "country_id": self.env.ref("base.bg").id}
)
# Data for 1T 2017
# Purchase invoices
p1 = self._invoice_purchase_create("2017-01-01")
p2 = self._invoice_purchase_create("2017-01-02")
# Create model
model349_model = self.env["l10n.es.aeat.mod349.report"].with_user(
self.account_manager
)
model349_1t = model349_model.create(
{
"name": "3490000000001",
"company_id": self.company.id,
"company_vat": "1234567890",
"contact_name": "Test owner",
"statement_type": "N",
"support_type": "T",
"contact_phone": "911234455",
"year": 2017,
"period_type": "1T",
"date_start": "2017-01-01",
"date_end": "2017-03-31",
}
)
# Calculate
_logger.debug("Calculate AEAT 349 1T 2017")
model349_1t.button_calculate()
self.assertEqual(model349_1t.total_partner_records, 1)
# p1 + p2 = 2400 + 2400 = 4800
self.assertEqual(model349_1t.total_partner_records_amount, 600.00)
self.assertEqual(model349_1t.total_partner_refunds, 0)
self.assertEqual(model349_1t.total_partner_refunds_amount, 0.0)
# Now create 2T 2017, refunding the first two bills
self._invoice_refund(p1, "2017-04-01")
self._invoice_refund(p2, "2017-04-02")
model349_2t = model349_model.create(
{
"name": "3490000000002",
"company_id": self.company.id,
"company_vat": "1234567890",
"contact_name": "Test owner",
"statement_type": "N",
"support_type": "T",
"contact_phone": "911234455",
"year": 2017,
"period_type": "2T",
"date_start": "2017-04-01",
"date_end": "2017-06-30",
}
)
# Calculate
_logger.debug("Calculate AEAT 349 2T 2017")
model349_2t.button_calculate()
self.assertEqual(model349_2t.total_partner_records, 0)
# p1 + p2 -
self.assertEqual(model349_2t.total_partner_records_amount, 0.0)
self.assertEqual(model349_2t.total_partner_refunds, 1)
self.assertEqual(model349_2t.total_partner_refunds_amount, 600.0)
a_refund = model349_2t.partner_refund_ids.filtered(
lambda x: x.operation_key == "A"
)
self.assertEqual(len(a_refund), 1)
self.assertEqual(len(a_refund.refund_detail_ids), 4)
self.assertEqual(a_refund.total_origin_amount, 600.0)
self.assertEqual(a_refund.total_operation_amount, 0.0)
Loading