diff options
| author | Dharmraj Jhala <dja@odoo.com> | 2019-05-02 07:22:49 +0000 |
|---|---|---|
| committer | Martin Geubelle <mge@odoo.com> | 2019-05-16 09:15:13 +0000 |
| commit | 35b778590a00f35284422dcddc748a429dcc348c (patch) | |
| tree | 16914826ed13b520bcc84fbafa5b0313e4bf88a4 /addons/web/static/src/js/fields | |
| parent | 7317f174c72171f6d4e7e44d99152833cb9208ee (diff) | |
[IMP] web: always use record data for signature widget 'full_name'
For signature field widget, we can set 'full_name' node option, which can be
used to auto fill the sign. However, current implementation for getting data
for field provided in 'full_name' (mainly, a string) has some flaws.
For example :
-In case of m2o fields, the string is not properly fetched due to different
structure than regular 'input' fields
- In case of x2m views inside a form view, field with same name can exist in
both parent record and child records. This is already the case with form view
of res.partner, where 'phone' field is there in both parent's form as well as
children's kanban view (for field 'child_ids'). With current implementation,
if we add signature on the form view, and set 'phone' as 'full_name' node
option, instead of form view, we will get phone number from 'child_ids'.
This commit improves the behavior by getting data from the 'recordData' instead
of searching them from the DOM. To have recordData in it's latest state, we've
set 'resetOnAnyFieldChange' flag to true.
task-1948364
closes odoo/odoo#33105
Signed-off-by: Martin Geubelle (mge) <mge@openerp.com>
Diffstat (limited to 'addons/web/static/src/js/fields')
| -rw-r--r-- | addons/web/static/src/js/fields/signature.js | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/addons/web/static/src/js/fields/signature.js b/addons/web/static/src/js/fields/signature.js index e2c4fc48836..6011cf7bf3f 100644 --- a/addons/web/static/src/js/fields/signature.js +++ b/addons/web/static/src/js/fields/signature.js @@ -116,6 +116,7 @@ var FieldBinarySignature = AbstractFieldBinary.extend({ fieldDependencies: _.extend({}, AbstractFieldBinary.prototype.fieldDependencies, { __last_update: {type: 'datetime'}, }), + resetOnAnyFieldChange: true, custom_events: _.extend({}, AbstractFieldBinary.prototype.custom_events, { upload_signature: '_onUploadSignature', }), @@ -231,18 +232,13 @@ var FieldBinarySignature = AbstractFieldBinary.extend({ }; if (this.nodeOptions.full_name) { - var $search = $("[name='" + this.nodeOptions.full_name + "']"); - // If full_name correspond to field in read-only mode - var signName = $($search).text(); - - // If full_name correspond to field to fill - if (!signName && $($search)[0]) { - signName = $($search)[0].value; - } - if (!signName) { - // If full_name is in the recordData. Last option because this value might not be the last value. - signName = this.recordData[this.nodeOptions.full_name] || ''; - } + var signName; + if (this.fields[this.nodeOptions.full_name].type === 'many2one') { + // If m2o is empty, it will have falsy value in recordData + signName = this.recordData[this.nodeOptions.full_name] && this.recordData[this.nodeOptions.full_name].data.display_name; + } else { + signName = this.recordData[this.nodeOptions.full_name]; + } nameAndSignatureOptions.defaultName = (signName === '') ? undefined : signName; } |
