Skip to content

Commit

Permalink
[RFC] l10n_br_portal: my/account form refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelsavegnago committed Jan 11, 2024
1 parent e3d6abb commit b0ba3ed
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 19 deletions.
1 change: 1 addition & 0 deletions l10n_br_portal/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright 2016 KMEE - Luis Felipe Miléo <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl
from . import controllers
from . import models
11 changes: 8 additions & 3 deletions l10n_br_portal/controllers/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ class L10nBrPortal(CustomerPortal):
"city_id",
"district",
"street_number",
"legal_name",
"cnpj_cpf",
"zipcode",
"inscr_est",
"street_name",
]
OPTIONAL_BILLING_FIELDS = list(
set(CustomerPortal.OPTIONAL_BILLING_FIELDS) - {"state_id"}
) + ["inscr_mun", "street2", "mobile"]
) + [
"legal_name",
"inscr_est",
"inscr_mun",
"street2",
"mobile",
"rg",
]

def _prepare_portal_layout_values(self):
values = super()._prepare_portal_layout_values()
Expand Down
1 change: 1 addition & 0 deletions l10n_br_portal/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import res_partner
15 changes: 15 additions & 0 deletions l10n_br_portal/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2023 - TODAY, Marcel Savegnago <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models


class ResPartner(models.Model):
_name = "res.partner"
_inherit = [_name, "l10n_br_base.party.mixin"]

def can_edit_vat(self):
can_edit_vat = super(ResPartner, self).can_edit_vat()
if not can_edit_vat:
return can_edit_vat

Check warning on line 14 in l10n_br_portal/models/res_partner.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_portal/models/res_partner.py#L14

Added line #L14 was not covered by tests
return not self.cnpj_cpf
22 changes: 16 additions & 6 deletions l10n_br_portal/static/src/js/l10n_br_portal_tour.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,31 @@ odoo.define("l10n_br_portal.tour", function (require) {
trigger: "input[name='name']",
run: "text Mileo",
},
{
content: "Complete Legal Name",
trigger: "input[name='legal_name']",
run: "text Luis Felipe Mileo",
},
{
content: "Complete CPF",
trigger: "input[name='cnpj_cpf']",
run: "text 89604455095",
},
{
content: "Complete IE",
content: "Complete Company Name",
trigger: "input[name='company_name']",
run: "text Empresa X",
},
{
content: "Complete Company CNPJ/VAT",
trigger: "input[name='vat']",
run: "text 34565346000159",
},
{
content: "Complete State Tax Number",
trigger: "input[name='inscr_est']",
run: "text ISENTO",
},
{
content: "Complete Municipal Tax Number",
trigger: "input[name='inscr_mun']",
run: "text 12345",
},
{
content: "Complete ZIP",
trigger: "input[name='zipcode']",
Expand Down
62 changes: 52 additions & 10 deletions l10n_br_portal/views/portal_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@
</div>

<div
t-if="user_id.partner_id.is_company == True"
t-attf-class="form-group #{error.get('legal_name') and 'o_has_error' or ''} col-xl-6"
>
<label
class="col-form-label label-optional"
for="legal_name"
>Razão Social / Nome Completo</label>
>Legal Name</label>
<p
t-if="not partner.can_edit_vat()"
t-attf-class="form-control"
Expand All @@ -71,9 +72,15 @@
t-attf-class="form-group #{error.get('cnpj_cpf') and 'o_has_error' or ''} col-xl-6"
>
<label
t-if="user_id.partner_id.is_company == False"
class="col-form-label label-optional"
for="cnpj_cpf"
>CNPJ/CPF</label>
>CPF</label>
<label
t-if="user_id.partner_id.is_company == True"
class="col-form-label label-optional"
for="cnpj_cpf"
>CNPJ/VAT</label>
<input
type="text"
name="cnpj_cpf"
Expand All @@ -83,38 +90,73 @@
t-att-title="None if partner.can_edit_vat() else 'Changing cnpj/cpf number is not allowed once document(s) have been issued for your account. Please contact us directly for this operation.'"
/>
</div>
<div class="clearfix" />
<div
t-if="user_id.partner_id.is_company == False"
t-attf-class="form-group #{error.get('company_name') and 'o_has_error' or ''} col-xl-6"
>
<label
class="col-form-label label-optional"
for="company_name"
>Company Name</label>
<!-- The <input> is replace by a <p> to avoid sending an unauthorized value on form submit.
The user might not have rights to change company_name but should still be able to see it.
-->
<input
type="text"
name="company_name"
t-attf-class="form-control #{error.get('company_name') and 'is-invalid' or ''}"
t-att-value="company_name or partner.commercial_company_name"
t-att-readonly="None if partner.can_edit_vat() else '1'"
/>
</div>
<div
t-if="user_id.partner_id.is_company == False"
t-attf-class="input-cnpj-cpf form-group #{error.get('vat') and 'o_has_error' or ''} col-xl-6"
>
<label
class="col-form-label label-optional"
for="vat"
>CNPJ/VAT</label>

<input
type="text"
name="vat"
t-attf-class="form-control #{error.get('vat') and 'is-invalid' or ''}"
t-att-value="vat or partner.vat"
t-att-readonly="None if partner.can_edit_vat() else '1'"
/>
</div>
<div
t-attf-class="form-group #{error.get('inscr_est') and 'o_has_error' or ''} col-xl-6"
>
<label
class="col-form-label label-optional"
for="inscr_est"
>IE/RG</label>
>State Tax Number</label>
<input
type="text"
name="inscr_est"
t-attf-class="form-control #{error.get('inscr_est') and 'is-invalid' or ''}"
t-att-value="inscr_est or partner.inscr_est"
t-att-readonly="None if partner.can_edit_vat() else '1'"
t-att-title="None if partner.can_edit_vat() else 'Changing IE/RG number is not allowed once document(s) have been issued for your account. Please contact us directly for this operation.'"
t-att-title="None if partner.can_edit_vat() else 'Changing State Tax Number is not allowed once document(s) have been issued for your account. Please contact us directly for this operation.'"
/>
</div>

<div
t-attf-class="form-group #{error.get('inscr_mun') and 'o_has_error' or ''} col-xl-6"
>
<label
class="col-form-label label-optional"
for="inscr_mun"
>Inscrição Municipal</label>
>Municipal Tax Number</label>
<input
type="text"
name="inscr_mun"
t-attf-class="form-control #{error.get('inscr_mun') and 'is-invalid' or ''}"
t-att-value="inscr_mun or partner.inscr_mun"
t-att-readonly="None if partner.can_edit_vat() else '1'"
t-att-title="None if partner.can_edit_vat() else 'Changing nscrição Municipal number is not allowed once document(s) have been issued for your account. Please contact us directly for this operation.'"
t-att-title="None if partner.can_edit_vat() else 'Changing Municipal Tax Number is not allowed once document(s) have been issued for your account. Please contact us directly for this operation.'"
/>
</div>

Expand Down Expand Up @@ -235,7 +277,7 @@
<label
class="col-form-label"
for="district"
>Bairro</label>
>District</label>
<input
type="text"
name="district"
Expand All @@ -250,7 +292,7 @@
<label
class="col-form-label"
for="street2"
>Complemento</label>
>Street2</label>
<input
type="text"
name="street2"
Expand Down Expand Up @@ -290,7 +332,7 @@
<label
class="col-form-label label-optional"
for="state_id"
>Cidade</label>
>City</label>
<select
name="city_id"
t-attf-class="form-control #{error.get('city_id') and 'is-invalid' or ''}"
Expand Down

0 comments on commit b0ba3ed

Please sign in to comment.