-
-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] l10n_br_account_withholding: handling of partner_id assignment
- Loading branch information
Showing
10 changed files
with
156 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import models | ||
from . import wizard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# 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" | ||
|
||
wh_cityhall = fields.Boolean("Is a WH City Hall", readonly=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_l10n_br_account_wh_wizard,access_l10n_br_account_wh_wizard,model_l10n_br_account_wh_wizard,account.group_account_invoice,1,1,1,0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?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="res_partner_form_view"> | ||
<field name="name">res.partner.form (in l10n_br_account_withholding)</field> | ||
<field name="model">res.partner</field> | ||
<field name="inherit_id" ref="base.view_partner_form" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//notebook" position="inside"> | ||
<page string="Withhoulding" name="partner_wh"> | ||
<label for="wh_cityhall" /> | ||
<field name="wh_cityhall" /> | ||
</page> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
<record id="res_partner_filter_view" model="ir.ui.view"> | ||
<field name="name">res.partner.filter (in l10n_br_account_withholding)</field> | ||
<field name="model">res.partner</field> | ||
<field name="inherit_id" ref="base.view_res_partner_filter" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//search" position="inside"> | ||
<separator /> | ||
<filter | ||
string="WH City Hall" | ||
name="wh_cityhall" | ||
domain="[('wh_cityhall', '=', True)]" | ||
/> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import l10n_br_account_wh_wizard |
51 changes: 51 additions & 0 deletions
51
l10n_br_account_withholding/wizard/l10n_br_account_wh_wizard.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Copyright (C) 2024 - TODAY, Kaynnan Lemes <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import _, fields, models | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class AccountWHWizard(models.TransientModel): | ||
""" | ||
A wizard to convert a res.partner record to a Withholding Partner | ||
""" | ||
|
||
_name = "l10n_br_account.wh.wizard" | ||
_description = "Partner WH Record Conversion" | ||
|
||
wh_record_type = fields.Selection([("cityhall", "City Hall")], "Record Type") | ||
|
||
def action_convert(self): | ||
partners = self.env["res.partner"].browse(self._context.get("active_ids", [])) | ||
for partner in partners: | ||
if self.wh_record_type == "cityhall": | ||
self.action_convert_cityhall(partner) | ||
else: | ||
self.action_reset_convert(partner) | ||
return {"type": "ir.actions.act_window_close"} | ||
|
||
def _prepare_wh_conversion(self, partner): | ||
return {"partner_id": partner.id} | ||
|
||
def action_convert_cityhall(self, partner): | ||
# Verify if there is already a partner with wh_cityhall=True in the same city | ||
existing_partner = self.env["res.partner"].search( | ||
[ | ||
("city_id", "=", partner.city_id.id), | ||
("wh_cityhall", "=", True), | ||
("id", "!=", partner.id), | ||
], | ||
limit=1, | ||
) | ||
|
||
if existing_partner: | ||
raise UserError( | ||
_("It is allowed to have only one City Hall partner per city.") | ||
) | ||
|
||
# If no such partner exists, proceed with the conversion | ||
self._prepare_wh_conversion(partner) | ||
partner.write({"wh_cityhall": True}) | ||
|
||
def action_reset_convert(self, partner): | ||
partner.write({"wh_cityhall": False}) | ||
38 changes: 38 additions & 0 deletions
38
l10n_br_account_withholding/wizard/l10n_br_account_wh_wizard.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<odoo> | ||
<!-- Res Partner Action --> | ||
<record id="partner_wh_action" model="ir.actions.act_window"> | ||
<field name="name">Convert to a Withholding Partner</field> | ||
<field name="res_model">l10n_br_account.wh.wizard</field> | ||
<field name="view_mode">form</field> | ||
<field name="target">new</field> | ||
<field name="binding_model_id" ref="base.model_res_partner" /> | ||
<field name="binding_view_types">form,list</field> | ||
<field name="groups_id" eval="[(4, ref('account.group_account_invoice'))]" /> | ||
</record> | ||
<!-- wizard view --> | ||
<record id="partner_wizard_view" model="ir.ui.view"> | ||
<field name="name">Convert to WH</field> | ||
<field name="model">l10n_br_account.wh.wizard</field> | ||
<field name="arch" type="xml"> | ||
<form string="Convert to a Partner Withholding"> | ||
<div> | ||
Select whether you want to convert this record to WH. | ||
</div> | ||
<group> | ||
<group> | ||
<field name="wh_record_type" widget="selection" /> | ||
</group> | ||
</group> | ||
<footer> | ||
<button | ||
string="Convert" | ||
name="action_convert" | ||
type="object" | ||
class="btn-primary" | ||
/> | ||
<button string="Cancel" class="btn-default" special="cancel" /> | ||
</footer> | ||
</form> | ||
</field> | ||
</record> | ||
</odoo> |