[FIX] account, [l10n_ar_]website_sale: always display b2b fields

Steps to reproduce:

  - Install `l10n_ar_website_sale` module

  - Go to shop (Argentinian website) and add a product to cart
  - Open cart and click on checkout
  - Click on Customize and disable `Show b2b fields` feature

Issue:

  Fields are no more displayed.

Cause:

  Since the b2b fields template (`address_b2b`) is customizable (meaning
  it can be enabled/disabled), it is possible for all countries to
  display/hide the b2b fields, but for some countries (for example
  Argentina) it should not; the b2b fields should always be displayed.

Solution:

  Add a method (`_display_partner_b2b_fields`) on website model to know
  if b2b fields should be displayed: return True if `address_b2b` view
  is active on current website or if the company (based on the country)
  must display them.

  Move content (b2b fields; vat and company name fields) of view
  `address_b2b` in `address` main view and let the `address_b2b` only be
  used as switch to display or hide the b2b fields.

  Add a condition in `address` view to display b2b fields only if the
  method `_display_partner_b2b_fields` returns `True`

opw-2941199

closes odoo/odoo#104505

X-original-commit: 1b5c85722db00a44ed8c6cb0c2bdba8905dc5292
Signed-off-by: Josse Colpaert <jco@odoo.com>
Signed-off-by: Nasreddin Boulif (bon) <bon@odoo.com>
This commit is contained in:
Nasreddin Boulif (bon)
2022-11-02 10:40:16 +01:00
parent 41d8bb8a28
commit 195bc157ab
6 changed files with 46 additions and 22 deletions
+1
View File
@@ -1,2 +1,3 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import controllers
from . import models
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import website
@@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models
class Website(models.Model):
_inherit = "website"
def _display_partner_b2b_fields(self):
""" Argentinean localization must always display b2b fields """
self.ensure_one()
return self.company_id.country_id.code == "AR" or super()._display_partner_b2b_fields()
@@ -43,7 +43,7 @@
</template>
<template id="address_b2b" inherit_id="website_sale.address_b2b">
<template id="address" inherit_id="website_sale.address">
<xpath expr="//input[@name='vat']/.." position="before">
<t t-if="mode[1] == 'billing'" positon="inside">
<t t-if="res_company.country_id.code == 'AR'">
+7
View File
@@ -543,6 +543,13 @@ class Website(models.Model):
template.send_mail(sale_order.id, email_values=dict(email_to=sale_order.partner_id.email))
sale_order.cart_recovery_email_sent = True
def _display_partner_b2b_fields(self):
""" This method is to be inherited by localizations and return
True if localization should always displayed b2b fields """
self.ensure_one()
return self.is_view_active('website_sale.address_b2b')
class WebsiteSaleExtraField(models.Model):
_name = 'website.sale.extra.field'
_description = 'E-Commerce Extra Info Shown on product page'
+20 -21
View File
@@ -1817,6 +1817,25 @@
<label class="col-form-label" for="phone">Phone</label>
<input type="tel" name="phone" t-attf-class="form-control #{error.get('phone') and 'is-invalid' or ''}" t-att-value="'phone' in checkout and checkout['phone']" />
</div>
<t t-if="website._display_partner_b2b_fields()">
<div class="w-100"/>
<t t-set='vat_warning' t-value="'vat' in checkout and checkout['vat'] and not can_edit_vat" />
<t t-if="mode == ('new', 'billing') or (mode == ('edit', 'billing') and (can_edit_vat or 'vat' in checkout and checkout['vat']))">
<div t-attf-class="mb-3 #{error.get('company_name') and 'o_has_error' or ''} col-lg-6 mb-0">
<label class="col-form-label fw-normal label-optional" for="company_name">Company Name</label>
<input type="text" name="company_name" t-attf-class="form-control #{error.get('company_name') and 'is-invalid' or ''}" t-att-value="'commercial_company_name' in checkout and checkout['commercial_company_name'] or 'company_name' in checkout and checkout['company_name']" t-att-readonly="'1' if vat_warning else None" />
<small t-if="vat_warning" class="form-text text-muted d-block d-lg-none">Changing company name is not allowed once document(s) have been issued for your account. Please contact us directly for this operation.</small>
</div>
<div t-attf-class="mb-3 #{error.get('vat') and 'o_has_error' or ''} col-lg-6 div_vat mb-0">
<label class="col-form-label fw-normal label-optional" for="vat">TIN / VAT </label>
<input type="text" name="vat" t-attf-class="form-control #{error.get('vat') and 'is-invalid' or ''}" t-att-value="'vat' in checkout and checkout['vat']" t-att-readonly="'1' if vat_warning else None"/>
<small t-if="vat_warning" class="form-text text-muted d-block d-lg-none">Changing VAT number is not allowed once document(s) have been issued for your account. Please contact us directly for this operation.</small>
</div>
<div t-if="vat_warning" class="col-12 d-none d-lg-block mb-1">
<small class="form-text text-muted">Changing company name or VAT number is not allowed once document(s) have been issued for your account. Please contact us directly for this operation.</small>
</div>
</t>
</t>
<div class="w-100"/>
<div t-attf-class="mb-3 #{error.get('street') and 'o_has_error' or ''} col-lg-12 div_street">
<label class="col-form-label" for="street">Street <span class="d-none d-md-inline"> and Number</span></label>
@@ -1906,27 +1925,7 @@
</t>
</template>
<template id="address_b2b" inherit_id="address" name="Show b2b fields">
<xpath expr="//div[@id='div_phone']" position="after">
<div class="w-100"/>
<t t-set='vat_warning' t-value="'vat' in checkout and checkout['vat'] and not can_edit_vat" />
<t t-if="mode == ('new', 'billing') or (mode == ('edit', 'billing') and (can_edit_vat or 'vat' in checkout and checkout['vat']))">
<div t-attf-class="mb-3 #{error.get('company_name') and 'o_has_error' or ''} col-lg-6 mb-0">
<label class="col-form-label fw-normal label-optional" for="company_name">Company Name</label>
<input type="text" name="company_name" t-attf-class="form-control #{error.get('company_name') and 'is-invalid' or ''}" t-att-value="'commercial_company_name' in checkout and checkout['commercial_company_name'] or 'company_name' in checkout and checkout['company_name']" t-att-readonly="'1' if vat_warning else None" />
<small t-if="vat_warning" class="form-text text-muted d-block d-lg-none">Changing company name is not allowed once document(s) have been issued for your account. Please contact us directly for this operation.</small>
</div>
<div t-attf-class="mb-3 #{error.get('vat') and 'o_has_error' or ''} col-lg-6 div_vat mb-0">
<label class="col-form-label fw-normal label-optional" for="vat">TIN / VAT </label>
<input type="text" name="vat" t-attf-class="form-control #{error.get('vat') and 'is-invalid' or ''}" t-att-value="'vat' in checkout and checkout['vat']" t-att-readonly="'1' if vat_warning else None"/>
<small t-if="vat_warning" class="form-text text-muted d-block d-lg-none">Changing VAT number is not allowed once document(s) have been issued for your account. Please contact us directly for this operation.</small>
</div>
<div t-if="vat_warning" class="col-12 d-none d-lg-block mb-1">
<small class="form-text text-muted">Changing company name or VAT number is not allowed once document(s) have been issued for your account. Please contact us directly for this operation.</small>
</div>
</t>
</xpath>
</template>
<template id="address_b2b" inherit_id="address" name="Show b2b fields" />
<template id="address_on_payment" name="Address on payment">
<div class="card">