-
-
Notifications
You must be signed in to change notification settings - Fork 498
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG+IMP]website_account_fiscal_position_partner_type: Standard migra…
…tion to 15.0, show fiscal position type in additional portal views
- Loading branch information
1 parent
efbf7d9
commit a6f1642
Showing
11 changed files
with
234 additions
and
3 deletions.
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
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import main | ||
from . import portal |
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,9 +1,10 @@ | ||
# Copyright 2021 Valentin Vinagre <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import http | ||
from odoo import _, http | ||
from odoo.http import request | ||
|
||
from odoo.addons.auth_signup.controllers.main import AuthSignupHome | ||
from odoo.addons.website_sale.controllers.main import WebsiteSale | ||
|
||
|
||
|
@@ -18,6 +19,39 @@ def values_postprocess(self, order, mode, values, errors, error_msg): | |
) | ||
return new_values, errors, error_msg | ||
|
||
def checkout_form_validate(self, mode, all_form_values, data): | ||
old_context = request.context | ||
request.context = dict( | ||
request.context, | ||
fiscal_position_type=all_form_values.get("fiscal_position_type"), | ||
) | ||
error, error_message = super().checkout_form_validate( | ||
mode, all_form_values, data | ||
) | ||
request.context = old_context | ||
if data.get("fiscal_position_type"): | ||
partner_su = ( | ||
request.env["res.partner"] | ||
.sudo() | ||
.browse(int(data["partner_id"])) | ||
.exists() | ||
) | ||
fiscal_position_type_change = ( | ||
partner_su | ||
and "fiscal_position_type" in data | ||
and data["fiscal_position_type"] != partner_su.fiscal_position_type | ||
) | ||
if fiscal_position_type_change and not partner_su.can_edit_vat(): | ||
error["fiscal_position_type"] = "error" | ||
error_message.append( | ||
_( | ||
"Changing partner type is not allowed once invoices have " | ||
"been issued for your account. Please contact us directly" | ||
" for this operation." | ||
) | ||
) | ||
return error, error_message | ||
|
||
@http.route() | ||
def address(self, **kw): | ||
res = super(WebsiteSale, self).address(**kw) | ||
|
@@ -49,3 +83,27 @@ def address(self, **kw): | |
} | ||
) | ||
return res | ||
|
||
|
||
class AuthSignupHome(AuthSignupHome): | ||
def get_auth_signup_qcontext(self): | ||
qcontext = super().get_auth_signup_qcontext() | ||
qcontext.update( | ||
{k: v for (k, v) in request.params.items() if k in {"fiscal_position_type"}} | ||
) | ||
afp_obj = request.env["account.fiscal.position"].sudo() | ||
qcontext["fiscpostypevalues"] = dict( | ||
afp_obj._fields["fiscal_position_type"].selection | ||
) | ||
if not qcontext.get("fiscal_position_type_selected"): | ||
def_fiscpostype = ( | ||
request.website.company_id.default_fiscal_position_type or "b2c" | ||
) | ||
qcontext["fiscal_position_type_selected"] = def_fiscpostype | ||
return qcontext | ||
|
||
def _prepare_signup_values(self, qcontext): | ||
values = super()._prepare_signup_values(qcontext) | ||
if "fiscal_position_type" in qcontext: | ||
values["fiscal_position_type"] = qcontext["fiscal_position_type"] | ||
return values |
44 changes: 44 additions & 0 deletions
44
website_account_fiscal_position_partner_type/controllers/portal.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,44 @@ | ||
# Copyright 2023 Manuel Regidor <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import _ | ||
from odoo.http import request | ||
|
||
from odoo.addons.portal.controllers.portal import CustomerPortal | ||
|
||
|
||
class CustomerPortal(CustomerPortal): | ||
|
||
CustomerPortal.OPTIONAL_BILLING_FIELDS += ["fiscal_position_type"] | ||
|
||
def details_form_validate(self, data): | ||
error, error_message = super().details_form_validate(data) | ||
partner = request.env.user.partner_id | ||
if ( | ||
not partner.can_edit_vat() | ||
and "fiscal_position_type" in data | ||
and data.get("fiscal_position_type") != partner.fiscal_position_type | ||
): | ||
error["fiscal_position_type"] = "error" | ||
error_message.append( | ||
_( | ||
"Changing Partner Type is not allowed once document(s) have " | ||
"been issued for your account. Please contact us directly for" | ||
" this operation." | ||
) | ||
) | ||
return error, error_message | ||
|
||
def _prepare_portal_layout_values(self): | ||
vals = super()._prepare_portal_layout_values() | ||
afp_obj = request.env["account.fiscal.position"].sudo() | ||
partner = request.env.user.partner_id | ||
vals.update( | ||
{ | ||
"fiscpostypevalues": dict( | ||
afp_obj._fields["fiscal_position_type"].selection | ||
), | ||
"fiscal_position_type_selected": partner.fiscal_position_type, | ||
} | ||
) | ||
return vals |
5 changes: 5 additions & 0 deletions
5
website_account_fiscal_position_partner_type/models/__init__.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,5 @@ | ||
# Copyright 2023 Manuel Regidor <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import res_users | ||
from . import res_partner |
15 changes: 15 additions & 0 deletions
15
website_account_fiscal_position_partner_type/models/res_partner.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,15 @@ | ||
# Copyright 2023 Manuel Regidor <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3). | ||
|
||
from odoo import api, models | ||
|
||
|
||
class Partner(models.Model): | ||
_inherit = "res.partner" | ||
|
||
@api.model | ||
def signup_retrieve_info(self, token): | ||
res = super().signup_retrieve_info(token) | ||
partner = self._signup_retrieve_partner(token, raise_exception=True) | ||
res.update({"fiscal_position_type_selected": partner.fiscal_position_type}) | ||
return res |
29 changes: 29 additions & 0 deletions
29
website_account_fiscal_position_partner_type/models/res_users.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,29 @@ | ||
# Copyright 2023 Manuel Regidor <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3). | ||
|
||
from odoo import api, models | ||
|
||
|
||
class ResUsers(models.Model): | ||
_inherit = "res.users" | ||
|
||
@api.model | ||
def signup(self, values, token=None): | ||
if token: | ||
partner = self.env["res.partner"]._signup_retrieve_partner( | ||
token, check_validity=True, raise_exception=True | ||
) | ||
partner_user = partner.user_ids and partner.user_ids[0] or False | ||
# Don't update fiscal_position_type if partner related to user | ||
# exists (i.e. when resetting password) | ||
if partner_user: | ||
values.pop("fiscal_position_type", None) | ||
return super().signup(values, token) | ||
|
||
def _create_user_from_template(self, values): | ||
user = super()._create_user_from_template(values) | ||
if user and user.partner_id and values.get("fiscal_position_type"): | ||
user.partner_id.write( | ||
{"fiscal_position_type": values.get("fiscal_position_type")} | ||
) | ||
return user |
35 changes: 35 additions & 0 deletions
35
website_account_fiscal_position_partner_type/views/auth_signup_login_templates.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,35 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- | ||
Copyright 2023 Manuel Regidor <[email protected]> | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
--> | ||
<odoo> | ||
<template | ||
id="website_account_fiscal_position_partner_type_auth_signup" | ||
inherit_id="auth_signup.fields" | ||
> | ||
<xpath expr="//div[hasclass('field-password')]" position="before"> | ||
<div class="form-group field-fiscalpositiontype"> | ||
<label | ||
class="col-form-label" | ||
for="fiscal_position_type" | ||
>Partner Type</label> | ||
<select | ||
id="fiscal_position_type" | ||
name="fiscal_position_type" | ||
class="form-control" | ||
t-att-disabled="'1' if only_passwords else None" | ||
> | ||
<t t-foreach="fiscpostypevalues" t-as="fptv"> | ||
<option | ||
t-att-selected="fiscal_position_type_selected == fptv" | ||
t-att-value="fptv" | ||
> | ||
<t t-esc="fiscpostypevalues[fptv]" /> | ||
</option> | ||
</t> | ||
</select> | ||
</div> | ||
</xpath> | ||
</template> | ||
</odoo> |
37 changes: 37 additions & 0 deletions
37
website_account_fiscal_position_partner_type/views/portal_templates.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,37 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- | ||
Copyright 2023 Manuel Regidor <[email protected]> | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
--> | ||
<odoo> | ||
<template | ||
id="website_checkoout_second_lastname_portal_my_details" | ||
inherit_id="portal.portal_my_details" | ||
> | ||
<xpath expr="//label[@for='vat']/.." position="after"> | ||
<div | ||
t-attf-class="form-group #{error.get('fiscal_position_type') and 'o_has_error' or ''} col-xl-6" | ||
> | ||
<label | ||
class="col-form-label" | ||
for="fiscal_position_type" | ||
>Partner Type</label> | ||
<select | ||
id="fiscal_position_type" | ||
name="fiscal_position_type" | ||
t-att-disabled="None if partner_can_edit_vat else '1'" | ||
t-attf-class="form-control #{error.get('fiscal_position_type') and 'is-invalid' or ''}" | ||
> | ||
<t t-foreach="fiscpostypevalues" t-as="fptv"> | ||
<option | ||
t-att-value="fptv" | ||
t-att-selected="fiscal_position_type_selected == fptv" | ||
> | ||
<t t-esc="fiscpostypevalues[fptv]" /> | ||
</option> | ||
</t> | ||
</select> | ||
</div> | ||
</xpath> | ||
</template> | ||
</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