[FIX] base, partner_autocomplete: remove vat from the partner selection field
Commita6e1eb9f0aintroduced the show_vat context key, that displays the Tax ID of a customer after its name when present, similarly to show_address. However it appears on the field when being edited, then disappears at save, which is confusing. Other unclean things tended to happen: you would have "name - taxid" on customer field, but "name" on invoice address and delivery address. Furthermore a client could edit the name manually to erase the Tax ID, and thus recreate a new record for the same customer. We introduce a method to clean the name from the Tax ID, and use it so that it is directly the client's name that is selected at edit. Note that we also replace the standard dash in the 'name - taxid' by a figuredash (‒, U+2012) so as to avoid potential egregious splits because of legitimate customer names. Similar to commit:3cbfc40303(same thing for show_address) opw 1911954 closes odoo/odoo#29189
This commit is contained in:
@@ -57,6 +57,19 @@ var PartnerField = FieldMany2One.extend({
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the display_name from a string which contains it but was altered
|
||||
* as a result of the show_vat option.
|
||||
* Note that the split is done on a 'figuredash', not a standard dash.
|
||||
*
|
||||
* @private
|
||||
* @param {string} value
|
||||
* @returns {string} display_name without TaxID
|
||||
*/
|
||||
_getDisplayNameWithoutVAT: function (value) {
|
||||
return value.split(' ‒ ')[0];
|
||||
},
|
||||
|
||||
/**
|
||||
* Modify autocomplete results rendering
|
||||
* Add logo in the autocomplete results if logo is provided
|
||||
@@ -91,6 +104,7 @@ var PartnerField = FieldMany2One.extend({
|
||||
* @private
|
||||
*/
|
||||
_renderEdit: function (){
|
||||
this.m2o_value = this._getDisplayNameWithoutVAT(this.m2o_value);
|
||||
this._super.apply(this, arguments);
|
||||
this._modifyAutompleteRendering();
|
||||
},
|
||||
|
||||
@@ -618,7 +618,7 @@ class Partner(models.Model):
|
||||
if self._context.get('html_format'):
|
||||
name = name.replace('\n', '<br/>')
|
||||
if self._context.get('show_vat') and partner.vat:
|
||||
name = "%s - %s" % (name, partner.vat)
|
||||
name = "%s ‒ %s" % (name, partner.vat)
|
||||
return name
|
||||
|
||||
@api.multi
|
||||
|
||||
Reference in New Issue
Block a user