Skip to content

Commit

Permalink
[ADD] #720 allow to enforce fiscal position requirements before bill …
Browse files Browse the repository at this point in the history
…validation
  • Loading branch information
hbrunn committed Oct 15, 2024
1 parent 691a8c5 commit 938cf5a
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 1 deletion.
1 change: 1 addition & 0 deletions bankayma_account/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"views/res_partner.xml",
"views/snippets.xml",
"views/templates.xml",
"views/tier_definition.xml",
"wizards/account_payment_register.xml",
"wizards/bankayma_company_create.xml",
"wizards/bankayma_move_change_company.xml",
Expand Down
1 change: 1 addition & 0 deletions bankayma_account/data/tier_definition.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<field name="has_comment" eval="True" />
<field name="comment_required_reject" eval="True" />
<field name="comment_required_validate" eval="False" />
<field name="bankayma_enforce_fpos_restrictions" eval="True" />
<field
name="server_action_id"
ref="action_post_validation_vendor_bill_confirm"
Expand Down
1 change: 1 addition & 0 deletions bankayma_account/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
from . import res_partner
from . import res_partner_bank
from . import res_users
from . import tier_definition
16 changes: 15 additions & 1 deletion bankayma_account/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from odoo.exceptions import UserError
from odoo.osv.expression import OR
from odoo.tests.common import Form
from odoo.tools import float_utils
from odoo.tools import float_utils, html2plaintext

from odoo.addons.account.models.account_move import PAYMENT_STATE_SELECTION

Expand Down Expand Up @@ -455,12 +455,26 @@ def request_validation(self):
):
raise UserError(_("Please set up proper product to request validation"))
result = super().request_validation()
for tier_review in result:
if tier_review.definition_id.bankayma_enforce_fpos_restrictions:
this = self.env[tier_review["model"]].browse(tier_review.res_id)
this.request_validation_check_fpos()

self.invalidate_recordset(["review_ids"])
self.env.add_to_compute(self._fields["validated_state"], self)
self.env.add_to_compute(self._fields["bankayma_intercompany_grouping"], self)
self._recompute_recordset(["validated_state", "bankayma_intercompany_grouping"])
return result

def request_validation_check_fpos(self):
if self.fiscal_position_id.vendor_doc_mandatory and not self.env[
"ir.attachment"
].search([("res_model", "=", self._name), ("res_id", "in", self.ids)]):
raise UserError(
_("Missing attachment: %s")
% html2plaintext(self.fiscal_position_id.vendor_doc_description)
)

def _portal_create_vendor_bill(self, post_data, uploaded_files):
company = self.env["res.company"].browse(
int(post_data.get("company", self.env.company.id))
Expand Down
12 changes: 12 additions & 0 deletions bankayma_account/models/tier_definition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2024 Hunki Enterprises BV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class TierDefinition(models.Model):
_inherit = "tier.definition"

bankayma_enforce_fpos_restrictions = fields.Boolean(
"Enforce fiscal position restrictions"
)
19 changes: 19 additions & 0 deletions bankayma_account/views/tier_definition.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2024 Hunki Enterprises BV
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="tier_definition_view_form" model="ir.ui.view">
<field name="model">tier.definition</field>
<field name="inherit_id" ref="base_tier_validation.tier_definition_view_form" />
<field name="arch" type="xml">
<group name="more_option" position="after">
<group name="bankayma_options">
<field
name="bankayma_enforce_fpos_restrictions"
attrs="{'invisible': [('model', '!=', 'account.move')]}"
/>
</group>
</group>
</field>
</record>
</odoo>

0 comments on commit 938cf5a

Please sign in to comment.