[FIX] account, portal, sale, website_sale: get correct company_name

This commit fixes multiple issues regarding the /shop/address and /my/account
forms where both are displaying `vat` and `company_name` fields.

1. For a company's child partner, the `company_name` was empty instead of
showing its company name (the name of its parent_id which is the commercial
entity).
2. It was possible for a child partner to edit its `vat` (which is a field
synced from parent to children, but only parent should be able to edit it as
it is the commercial entity, see 4a1bc45934 and 98b1fffd4e).
3. Company name now share the exact same condition than the vat field in order
to be editable (as it should have been). It was possible to edit vat but not
company name on /my/account.

Steps to reproduce the bug:

- Create a company contact CO with a VAT number
- Create a contact C in CO with portal access
- Log with C and go to the shop
- In the checkout, try to edit the address details

opw-2007368

closes odoo/odoo#34564

Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
This commit is contained in:
Romain Derie
2019-07-04 08:48:50 +00:00
parent d82b897ea1
commit 8b55cdd7af
5 changed files with 12 additions and 4 deletions
+1
View File
@@ -451,6 +451,7 @@ class ResPartner(models.Model):
return {'domain': {'property_account_position_id': [('company_id', 'in', [company.id, False])]}}
def can_edit_vat(self):
''' Can't edit `vat` if there is (non draft) issued invoices. '''
can_edit_vat = super(ResPartner, self).can_edit_vat()
if not can_edit_vat:
return can_edit_vat
+4 -1
View File
@@ -8,4 +8,7 @@ class ResPartner(models.Model):
_inherit = 'res.partner'
def can_edit_vat(self):
return True
''' `vat` is a commercial field, synced between the parent (commercial
entity) and the children. Only the commercial entity should be able to
edit it (as in backend). '''
return not self.parent_id
+5 -2
View File
@@ -378,8 +378,11 @@
<div class="clearfix" />
<div 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>
<p t-if="partner.commercial_partner_id.is_company" t-attf-class="form-control #{error.get('company_name') and 'is-invalid' or ''}" t-esc="partner.commercial_company_name"/>
<input t-else="" 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.company_name" t-att-readonly="None if partner.can_edit_vat() else '1'" t-att-title="None if partner.can_edit_vat() else 'Changing company name is not allowed once document(s) have been issued for your account. Please contact us directly for this operation.'"/>
<!-- 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.
-->
<p t-if="not partner.can_edit_vat()" t-attf-class="form-control" readonly="1" t-esc="partner.commercial_company_name" title="Changing company name is not allowed once document(s) have been issued for your account. Please contact us directly for this operation."/>
<input t-else="" 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"/>
</div>
<div t-attf-class="form-group #{error.get('vat') and 'o_has_error' or ''} col-xl-6">
<label class="col-form-label label-optional" for="vat">VAT Number</label>
+1
View File
@@ -30,6 +30,7 @@ class ResPartner(models.Model):
partner = partner.parent_id
def can_edit_vat(self):
''' Can't edit `vat` if there is (non draft) issued SO. '''
can_edit_vat = super(ResPartner, self).can_edit_vat()
if not can_edit_vat:
return can_edit_vat
+1 -1
View File
@@ -1286,7 +1286,7 @@
<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="form-group #{error.get('company_name') and 'o_has_error' or ''} col-lg-6">
<label class="col-form-label font-weight-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="'company_name' in checkout and checkout['company_name']" t-att-readonly="'1' if 'vat' in checkout and checkout['vat'] and not can_edit_vat else None" t-att-title="'Changing company name is not allowed once document(s) have been issued for your account. Please contact us directly for this operation.' if 'vat' in checkout and checkout['vat'] and not can_edit_vat else None" />
<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' in checkout and checkout['vat'] and not can_edit_vat else None" t-att-title="'Changing company name is not allowed once document(s) have been issued for your account. Please contact us directly for this operation.' if 'vat' in checkout and checkout['vat'] and not can_edit_vat else None" />
</div>
<div t-attf-class="form-group #{error.get('vat') and 'o_has_error' or ''} col-lg-6 div_vat">
<label class="col-form-label font-weight-normal label-optional" for="vat">TIN / VAT </label>