Skip to content

Commit

Permalink
[IMP] l10n_br_account_withholding: handling of partner_id assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
kaynnan committed Aug 7, 2024
1 parent 0ea78da commit acf5214
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
1 change: 1 addition & 0 deletions l10n_br_account_withholding/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"l10n_br_account",
],
"data": [
"views/res_partner.xml",
"views/l10n_br_fiscal_tax_group.xml",
"views/account_move.xml",
],
Expand Down
1 change: 1 addition & 0 deletions l10n_br_account_withholding/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import account_move
from . import l10n_br_fiscal_tax_group
from . import account_move_line
from . import res_partner
16 changes: 15 additions & 1 deletion l10n_br_account_withholding/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (

Check warning on line 83 in l10n_br_account_withholding/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account_withholding/models/account_move.py#L83

Added line #L83 was not covered by tests
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(

Check warning on line 88 in l10n_br_account_withholding/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account_withholding/models/account_move.py#L88

Added line #L88 was not covered by tests
[("city_id", "=", city_id.id), ("wh_cityhall", "=", True)], limit=1
)
partner_id = partner_wh if partner_wh else fiscal_group.partner_id

Check warning on line 91 in l10n_br_account_withholding/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account_withholding/models/account_move.py#L91

Added line #L91 was not covered by tests
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),
Expand Down
20 changes: 20 additions & 0 deletions l10n_br_account_withholding/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2024 - TODAY, Kaynnan Lemes <[email protected]>
# 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 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.",
),
]
19 changes: 19 additions & 0 deletions l10n_br_account_withholding/views/res_partner.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2024 - TODAY, Kaynnan Lemes <[email protected]>
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>

<record model="ir.ui.view" id="partner_form_view">
<field
name="name"
>l10n_br_fiscal.partner.form (in l10n_br_account_withholding)</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="l10n_br_base.l10n_br_base_partner_form" />
<field name="arch" type="xml">
<xpath expr="//group[@name='other_infos']" position="inside">
<field name="wh_cityhall" />
</xpath>
</field>
</record>

</odoo>

0 comments on commit acf5214

Please sign in to comment.