diff --git a/l10n_br_account_withholding/__manifest__.py b/l10n_br_account_withholding/__manifest__.py index a84e12d3e499..0a2043ecfffa 100644 --- a/l10n_br_account_withholding/__manifest__.py +++ b/l10n_br_account_withholding/__manifest__.py @@ -14,6 +14,7 @@ "l10n_br_account", ], "data": [ + "views/res_city.xml", "views/l10n_br_fiscal_tax_group.xml", "views/account_move.xml", ], diff --git a/l10n_br_account_withholding/models/__init__.py b/l10n_br_account_withholding/models/__init__.py index e958216983e8..c78bd8004979 100644 --- a/l10n_br_account_withholding/models/__init__.py +++ b/l10n_br_account_withholding/models/__init__.py @@ -1,3 +1,4 @@ from . import account_move from . import l10n_br_fiscal_tax_group from . import account_move_line +from . import res_city diff --git a/l10n_br_account_withholding/models/account_move.py b/l10n_br_account_withholding/models/account_move.py index 68918e32b4fa..e18cbf7bf594 100644 --- a/l10n_br_account_withholding/models/account_move.py +++ b/l10n_br_account_withholding/models/account_move.py @@ -78,8 +78,18 @@ def _prepare_wh_invoice(self, move_line, fiscal_group): """ wh_date_invoice = move_line.move_id.date wh_due_invoice = wh_date_invoice.replace(day=fiscal_group.wh_due_day) + + city_id = ( + self.invoice_line_ids[0].issqn_fg_city_id + if self.invoice_line_ids[0].issqn_fg_city_id + else self.partner_id.city_id + ) + partner_id = ( + city_id.partner_wh_id if city_id.partner_wh_id else fiscal_group.partner_id + ) + values = { - "partner_id": fiscal_group.partner_id.id, + "partner_id": partner_id, "date": wh_date_invoice, "invoice_date": wh_date_invoice, "invoice_date_due": wh_due_invoice + relativedelta(months=1), diff --git a/l10n_br_account_withholding/models/res_city.py b/l10n_br_account_withholding/models/res_city.py new file mode 100644 index 000000000000..4c05f11d3f44 --- /dev/null +++ b/l10n_br_account_withholding/models/res_city.py @@ -0,0 +1,15 @@ +# Copyright 2024 - TODAY, Kaynnan Lemes +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResCity(models.Model): + + _inherit = "res.city" + + partner_wh_id = fields.Many2one( + comodel_name="res.partner", + string="WH Partner", + help="Partner associated with this city for withholding tax purposes" + ) diff --git a/l10n_br_account_withholding/views/res_city.xml b/l10n_br_account_withholding/views/res_city.xml new file mode 100644 index 000000000000..a3613e40b3b0 --- /dev/null +++ b/l10n_br_account_withholding/views/res_city.xml @@ -0,0 +1,15 @@ + + + + + res.city.tree + res.city + + + + + + + +