Skip to content

Commit

Permalink
[FIX] l10n_es_aeat_mod369: Differ between other period refunds
Browse files Browse the repository at this point in the history
  • Loading branch information
aritzolea committed Oct 17, 2023
1 parent 983fc43 commit 5f633a0
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 45 deletions.
9 changes: 6 additions & 3 deletions l10n_es_aeat_mod369/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-10-10 11:50+0000\n"
"PO-Revision-Date: 2023-10-10 13:53+0200\n"
"POT-Creation-Date: 2023-10-17 11:49+0000\n"
"PO-Revision-Date: 2023-10-17 13:50+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: es\n"
Expand Down Expand Up @@ -130,7 +130,7 @@ msgstr "Cuenta bancaria"
#. module: l10n_es_aeat_mod369
#: model:ir.model.fields,field_description:l10n_es_aeat_mod369.field_l10n_es_aeat_mod369_line_grouped__base
msgid "Base total"
msgstr "Base total"
msgstr ""

#. module: l10n_es_aeat_mod369
#: model:ir.model.fields,field_description:l10n_es_aeat_mod369.field_l10n_es_aeat_mod369_report__calculation_date
Expand Down Expand Up @@ -705,16 +705,19 @@ msgstr "Saldo para ingresar en España"

#. module: l10n_es_aeat_mod369
#: model:ir.model.fields,field_description:l10n_es_aeat_mod369.field_l10n_es_aeat_mod369_line_grouped__result_total
#: model_terms:ir.ui.view,arch_db:l10n_es_aeat_mod369.view_l10n_es_aeat_mod369_report_form
msgid "Total result"
msgstr "Resultado total"

#. module: l10n_es_aeat_mod369
#: model:ir.model.fields,field_description:l10n_es_aeat_mod369.field_l10n_es_aeat_mod369_line_grouped__total_deposit
#: model_terms:ir.ui.view,arch_db:l10n_es_aeat_mod369.view_l10n_es_aeat_mod369_report_form
msgid "Total to deposit ES"
msgstr "Total a ingresar ES"

#. module: l10n_es_aeat_mod369
#: model:ir.model.fields,field_description:l10n_es_aeat_mod369.field_l10n_es_aeat_mod369_line_grouped__total_return
#: model_terms:ir.ui.view,arch_db:l10n_es_aeat_mod369.view_l10n_es_aeat_mod369_report_form
msgid "Total to return EM"
msgstr "Total a devolver EM"

Expand Down
7 changes: 5 additions & 2 deletions l10n_es_aeat_mod369/i18n/l10n_es_aeat_mod369.pot
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-10-10 11:54+0000\n"
"PO-Revision-Date: 2023-10-10 11:54+0000\n"
"POT-Creation-Date: 2023-10-17 11:49+0000\n"
"PO-Revision-Date: 2023-10-17 11:49+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -695,16 +695,19 @@ msgstr ""

#. module: l10n_es_aeat_mod369
#: model:ir.model.fields,field_description:l10n_es_aeat_mod369.field_l10n_es_aeat_mod369_line_grouped__result_total
#: model_terms:ir.ui.view,arch_db:l10n_es_aeat_mod369.view_l10n_es_aeat_mod369_report_form
msgid "Total result"
msgstr ""

#. module: l10n_es_aeat_mod369
#: model:ir.model.fields,field_description:l10n_es_aeat_mod369.field_l10n_es_aeat_mod369_line_grouped__total_deposit
#: model_terms:ir.ui.view,arch_db:l10n_es_aeat_mod369.view_l10n_es_aeat_mod369_report_form
msgid "Total to deposit ES"
msgstr ""

#. module: l10n_es_aeat_mod369
#: model:ir.model.fields,field_description:l10n_es_aeat_mod369.field_l10n_es_aeat_mod369_line_grouped__total_return
#: model_terms:ir.ui.view,arch_db:l10n_es_aeat_mod369.view_l10n_es_aeat_mod369_report_form
msgid "Total to return EM"
msgstr ""

Expand Down
63 changes: 31 additions & 32 deletions l10n_es_aeat_mod369/models/mod369.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,14 @@ def calculate(self):
}
country_groups = {}
tax_lines = report.mapped("tax_line_ids")
for line in tax_lines.filtered(lambda l: len(l.move_line_ids) > 0):
for line in tax_lines.filtered(lambda tl: len(tl.move_line_ids) > 0):
mod369_line = line.mod369_line_id
move_lines = line.move_line_ids.filtered(
lambda l: l.move_type == "out_invoice"
ref_move_lines = line.move_line_ids.filtered(
lambda ml: ml.move_type == "out_refund"
and ml.move_id.reversed_entry_id
and ml.move_id.reversed_entry_id.invoice_date < report.date_start
)
move_lines = line.move_line_ids - ref_move_lines
country = mod369_line.country_id
oss_country = mod369_line.oss_country_id
tax = mod369_line.oss_tax_id
Expand Down Expand Up @@ -293,37 +296,33 @@ def calculate(self):
},
)
country_groups[country.id]["mod369_line_ids"] += [(4, mod369_line.id)]
ref_move_lines = line.move_line_ids.filtered(
lambda ml: ml.move_type == "out_refund"
and ml.move_id.reversed_entry_id
)
for mline in ref_move_lines:
orig_move = mline.move_id.reversed_entry_id
if orig_move.invoice_date < report.date_start:
refund_fiscal_year = orig_move.date.year
refund_period = self._get_period_from_date(orig_move.date)
key = "{}{}{}".format(
country.id,
refund_fiscal_year,
refund_period,
)
country_groups.setdefault(
key,
{
"country_id": country.id,
"oss_country_id": oss_country.id,
"mod369_line_ids": [],
"refund_line_ids": [],
"report_id": report.id,
"is_refund": True,
"refund_fiscal_year": refund_fiscal_year,
"refund_period": refund_period,
"tax_correction": 0,
},
)
if line.map_line_id.field_type == "amount":
country_groups[key]["tax_correction"] += mline.debit
country_groups[key]["refund_line_ids"] += [(4, mline.id)]
refund_fiscal_year = orig_move.date.year
refund_period = self._get_period_from_date(orig_move.date)
key = "{}{}{}".format(
country.id,
refund_fiscal_year,
refund_period,
)
# page 7
country_groups.setdefault(
key,
{
"country_id": country.id,
"oss_country_id": oss_country.id,
"mod369_line_ids": [],
"refund_line_ids": [],
"report_id": report.id,
"is_refund": True,
"refund_fiscal_year": refund_fiscal_year,
"refund_period": refund_period,
"tax_correction": 0,
},
)
if line.map_line_id.field_type == "amount":
country_groups[key]["tax_correction"] += mline.debit
country_groups[key]["refund_line_ids"] += [(4, mline.id)]

groups = self.env["l10n.es.aeat.mod369.line.grouped"].create(
list(country_groups.values())
Expand Down
18 changes: 13 additions & 5 deletions l10n_es_aeat_mod369/models/mod369_line_grouped.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ def _compute_totals(self):
"total_deposit": 0,
"total_return": 0,
}
report = group.report_id
for line in group.mod369_line_ids:
move_lines = line.tax_line_id.move_line_ids.filtered(
lambda ml: ml.move_type == "out_invoice"
ref_move_lines = line.tax_line_id.move_line_ids.filtered(
lambda ml: ml.move_type == "out_refund"
and ml.move_id.reversed_entry_id
and ml.move_id.reversed_entry_id.invoice_date < report.date_start
)
move_lines = line.tax_line_id.move_line_ids - ref_move_lines
amount = sum(move_lines.mapped("credit"))
amount -= sum(move_lines.mapped("debit"))
group_keys[line.map_line_id.field_type] += amount
if not group.is_page_8_line or line.map_line_id.field_type != "amount":
continue
Expand Down Expand Up @@ -128,10 +133,13 @@ def get_calculated_move_lines(self):
res = self.env.ref("account.action_account_moves_all_a").sudo().read()[0]
view = self.env.ref("l10n_es_aeat.view_move_line_tree")
res["views"] = [(view.id, "tree")]
move_lines = self.mapped("mod369_line_ids.tax_line_id.move_line_ids").filtered(
lambda ml: ml.move_type == "out_invoice"
move_lines = self.mapped("mod369_line_ids.tax_line_id.move_line_ids")
ref_move_lines = move_lines.filtered(
lambda ml: ml.move_type == "out_refund"
and ml.move_id.reversed_entry_id
and ml.move_id.reversed_entry_id.invoice_date < self.report_id.date_start
)
res["domain"] = [("id", "in", move_lines.ids)]
res["domain"] = [("id", "in", (move_lines - ref_move_lines).ids)]
return res

def get_calculated_refund_move_lines(self):
Expand Down
6 changes: 3 additions & 3 deletions l10n_es_aeat_mod369/views/mod369_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@
/>
<field name="pos_corrections" optional="hide" />
<field name="neg_corrections" optional="hide" />
<field name="result_total" optional="hide" />
<field name="total_deposit" optional="hide" />
<field name="total_return" optional="hide" />
<field name="result_total" sum="Total result" optional="hide" />
<field name="total_deposit" sum="Total to deposit ES" optional="hide" />
<field name="total_return" sum="Total to return EM" optional="hide" />
</tree>
</field>
</page>
Expand Down

0 comments on commit 5f633a0

Please sign in to comment.