Skip to content

Commit e627b80

Browse files
[FIX] l10n_es_aeat_mod349: refund intermediate periods
1 parent aaab270 commit e627b80

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed

l10n_es_aeat_mod349/models/mod349.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,24 @@ def _create_349_refund_records(self):
229229
origin_amount = sum(original_details.mapped("amount_untaxed"))
230230
period_type = report.period_type
231231
year = str(report.year)
232+
# If there are intermediate periods between the original period
233+
# and the period where the rectification is taking place, it's
234+
# necessary to check if there is any rectification of the
235+
# original period in between these periods. This happens in
236+
# this way because the right original_amount will be the value
237+
# of the total_operation_amount corresponding to the last
238+
# period found in between the periods.
239+
last_refund_detail = refund_detail_obj.search(
240+
[
241+
("report_id.date_start", ">", report.date_end),
242+
("report_id.date_end", "<", self.date_start),
243+
("move_id", "in", origin_invoice.reversal_move_id.ids),
244+
],
245+
order="date desc",
246+
limit=1,
247+
)
248+
if last_refund_detail:
249+
origin_amount = last_refund_detail.refund_id.total_operation_amount
232250
else:
233251
# There's no previous 349 declaration report in Odoo
234252
original_amls = move_line_obj.search(

l10n_es_aeat_mod349/tests/test_l10n_es_aeat_mod349.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44

55
import logging
66

7+
from odoo.tests.common import Form, tagged
8+
79
from odoo.addons.l10n_es_aeat.tests.test_l10n_es_aeat_mod_base import (
810
TestL10nEsAeatModBase,
911
)
1012

1113
_logger = logging.getLogger("aeat.349")
1214

1315

16+
@tagged("post_install", "-at_install")
1417
class TestL10nEsAeatMod349Base(TestL10nEsAeatModBase):
1518
# Set 'debug' attribute to True to easy debug this test
1619
# Do not forget to include '--log-handler aeat:DEBUG' in Odoo command line
@@ -23,6 +26,32 @@ class TestL10nEsAeatMod349Base(TestL10nEsAeatModBase):
2326
"P_IVA21_IC_BC//2": (150, 0),
2427
}
2528

29+
@classmethod
30+
def _invoice_refund(cls, invoice, dt, price_unit=None):
31+
_logger.debug(
32+
"Refund {} invoice: date = {}: price_unit = {}".format(
33+
invoice.move_type, dt, price_unit or 150.0
34+
)
35+
)
36+
default_values_list = [
37+
{
38+
"date": dt,
39+
"invoice_date": dt,
40+
"invoice_payment_term_id": None,
41+
}
42+
]
43+
inv = invoice.with_user(cls.billing_user)._reverse_moves(default_values_list)
44+
if price_unit is not None:
45+
inv_lines = inv.invoice_line_ids
46+
with Form(inv) as inv_form:
47+
for i in range(len(inv_lines)):
48+
with inv_form.invoice_line_ids.edit(i) as line:
49+
line.price_unit = price_unit or 150.0
50+
inv.action_post()
51+
if cls.debug:
52+
cls._print_move_lines(inv.line_ids)
53+
return inv
54+
2655
def test_model_349(self):
2756
# Add some test data
2857
self.customer.write(
@@ -210,3 +239,79 @@ def test_model_349(self):
210239
self.env.ref("l10n_es_aeat_mod349.act_report_aeat_mod349_pdf")._render(
211240
model349.ids
212241
)
242+
243+
def test_model_349_with_intermediate_periods(self):
244+
# Create vendor bill and 2 refunds in different periods
245+
inv = self._invoice_purchase_create("2017-01-01")
246+
self._invoice_refund(inv, "2017-02-01", price_unit=50)
247+
self._invoice_refund(inv, "2017-03-01", price_unit=50)
248+
# Create model
249+
model349_model = self.env["l10n.es.aeat.mod349.report"].with_user(
250+
self.account_manager
251+
)
252+
model349_1 = model349_model.create(
253+
{
254+
"name": "3490000000001",
255+
"company_id": self.company.id,
256+
"company_vat": "1234567890",
257+
"contact_name": "Test owner",
258+
"statement_type": "N",
259+
"support_type": "T",
260+
"contact_phone": "911234455",
261+
"year": 2017,
262+
"period_type": "01",
263+
"date_start": "2017-01-01",
264+
"date_end": "2017-01-31",
265+
}
266+
)
267+
# Calculate
268+
_logger.debug("Calculate AEAT 349 January 2017")
269+
model349_1.button_calculate()
270+
self.assertEqual(model349_1.total_partner_records, 1)
271+
self.assertEqual(model349_1.partner_record_ids.total_operation_amount, 300)
272+
273+
model349_2 = model349_model.create(
274+
{
275+
"name": "3490000000002",
276+
"company_id": self.company.id,
277+
"company_vat": "1234567890",
278+
"contact_name": "Test owner",
279+
"statement_type": "N",
280+
"support_type": "T",
281+
"contact_phone": "911234455",
282+
"year": 2017,
283+
"period_type": "02",
284+
"date_start": "2017-02-01",
285+
"date_end": "2017-02-28",
286+
}
287+
)
288+
# Calculate
289+
_logger.debug("Calculate AEAT 349 February 2017")
290+
model349_2.button_calculate()
291+
self.assertEqual(model349_2.total_partner_records, 0)
292+
self.assertEqual(model349_2.total_partner_refunds, 1)
293+
self.assertEqual(model349_2.partner_refund_ids.total_origin_amount, 300)
294+
self.assertEqual(model349_2.partner_refund_ids.total_operation_amount, 200)
295+
296+
model349_3 = model349_model.create(
297+
{
298+
"name": "3490000000003",
299+
"company_id": self.company.id,
300+
"company_vat": "1234567890",
301+
"contact_name": "Test owner",
302+
"statement_type": "N",
303+
"support_type": "T",
304+
"contact_phone": "911234455",
305+
"year": 2017,
306+
"period_type": "03",
307+
"date_start": "2017-03-01",
308+
"date_end": "2017-03-31",
309+
}
310+
)
311+
# Calculate
312+
_logger.debug("Calculate AEAT 349 March 2017")
313+
model349_3.button_calculate()
314+
self.assertEqual(model349_3.total_partner_records, 0)
315+
self.assertEqual(model349_3.total_partner_refunds, 1)
316+
self.assertEqual(model349_3.partner_refund_ids.total_origin_amount, 200)
317+
self.assertEqual(model349_3.partner_refund_ids.total_operation_amount, 100)

0 commit comments

Comments
 (0)