diff --git a/l10n_br_account_withholding/__manifest__.py b/l10n_br_account_withholding/__manifest__.py index a84e12d3e499..27a858a077bd 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_partner.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..d5d20ae7e74a 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_partner diff --git a/l10n_br_account_withholding/models/account_move.py b/l10n_br_account_withholding/models/account_move.py index 68918e32b4fa..918b164acfd0 100644 --- a/l10n_br_account_withholding/models/account_move.py +++ b/l10n_br_account_withholding/models/account_move.py @@ -78,8 +78,22 @@ 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) + + if fiscal_group.tax_scope == "city": + 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_wh = self.env["res.partner"].search( + [("city_id", "=", city_id.id), ("wh_cityhall", "=", True)], limit=1 + ) + partner_id = partner_wh if partner_wh else fiscal_group.partner_id + else: + partner_id = fiscal_group.partner_id + values = { - "partner_id": fiscal_group.partner_id.id, + "partner_id": partner_id.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_partner.py b/l10n_br_account_withholding/models/res_partner.py new file mode 100644 index 000000000000..a7a386cd77b4 --- /dev/null +++ b/l10n_br_account_withholding/models/res_partner.py @@ -0,0 +1,20 @@ +# Copyright 2024 - TODAY, Kaynnan Lemes +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResPartner(models.Model): + + _inherit = "res.partner" + + # TODO: Add WH fields for State and Country + wh_cityhall = fields.Boolean(string="Is a Partner WH City Hall") + + _sql_constraints = [ + ( + "unique_wh_cityhall", + "UNIQUE(city_id, wh_cityhall)", + "Only one partner with the same City Hall can exist in the same city.", + ), + ] diff --git a/l10n_br_account_withholding/views/res_partner.xml b/l10n_br_account_withholding/views/res_partner.xml new file mode 100644 index 000000000000..6705c8cda9a7 --- /dev/null +++ b/l10n_br_account_withholding/views/res_partner.xml @@ -0,0 +1,23 @@ + + + + + + l10n_br_fiscal.partner.form (in l10n_br_account_withholding) + res.partner + + + + + + + + + + + + +