Merge lp:~jfb-tempo-consulting/unifield-web/US-8372 into lp:unifield-web

Proposed by jftempo
Status: Merged
Merged at revision: 5014
Proposed branch: lp:~jfb-tempo-consulting/unifield-web/US-8372
Merge into: lp:unifield-web
Diff against target: 161 lines (+47/-9)
6 files modified
addons/openerp/static/javascript/form.js (+13/-2)
addons/openerp/static/javascript/listgrid.js (+10/-1)
addons/openerp/utils/utils.py (+1/-1)
addons/openerp/validators.py (+10/-2)
addons/openerp/widgets/form/_form.py (+5/-2)
addons/openerp/widgets/form/templates/float.mako (+8/-1)
To merge this branch: bzr merge lp:~jfb-tempo-consulting/unifield-web/US-8372
Reviewer Review Type Date Requested Status
UniField Dev Team Pending
Review via email: mp+401183@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'addons/openerp/static/javascript/form.js'
2--- addons/openerp/static/javascript/form.js 2020-12-22 09:41:29 +0000
3+++ addons/openerp/static/javascript/form.js 2021-04-15 08:08:39 +0000
4@@ -261,8 +261,10 @@
5 if (!value) {
6 jQuery(elem2).addClass('errorfield');
7 result = false;
8- }
9- else
10+ } else if (kind == 'float' && jQuery(elem).attr('en_thousand_sep') && value.indexOf(',') !== -1) {
11+ jQuery(elem2).addClass('errorfield');
12+ result = false;
13+ } else
14 if (jQuery(elem2).hasClass('errorfield')) {
15 jQuery(elem2).removeClass('errorfield');
16 }
17@@ -508,8 +510,12 @@
18 */
19 function getFormData(extended, include_readonly, parentNode) {
20
21+ var from_evaldom_ctx = false;
22 if (!parentNode) {
23 var parentNode = openobject.dom.get('_terp_list') || document.forms['view_form'];
24+ if (extended == 1) {
25+ from_evaldom_ctx = true;
26+ }
27 }
28
29 var frm = {};
30@@ -614,6 +620,11 @@
31 attrs['required'] = 1;
32 }
33
34+ /* onchange: extended =1, save extended = 3 */
35+ if ((extended == 3 || !from_evaldom_ctx) && kind == 'float' && $this.attr('en_thousand_sep')) {
36+ attrs['en_thousand_sep'] = $this.attr('en_thousand_sep');
37+ }
38+
39 switch (kind) {
40 case "picture":
41 name = this.id;
42
43=== modified file 'addons/openerp/static/javascript/listgrid.js'
44--- addons/openerp/static/javascript/listgrid.js 2020-12-23 15:44:38 +0000
45+++ addons/openerp/static/javascript/listgrid.js 2021-04-15 08:08:39 +0000
46@@ -823,7 +823,7 @@
47 var self = this;
48 var req = openobject.http.postJSON('/openerp/listgrid/save', args);
49
50- var $current_record = jQuery('table[id="'+this.name+'_grid'+'"]').find('tr.grid-row[record="'+id+'"]');
51+ var $current_record = jQuery('table[id="'+this.name+'_grid'+'"]').find('tr.grid-row[record="'+(id||-1)+'"]');
52 req.addCallback(function(obj) {
53 if (obj.error) {
54 error_display(obj.error);
55@@ -848,6 +848,15 @@
56 $req_field.removeClass('errorfield');
57 }
58 }
59+ if (obj.error_field) {
60+ var $field_error = $current_record.find('td [id="'+'_terp_listfields/'+obj.error_field+'"]');
61+ if ($field_error.length) {
62+ $field_error.addClass('errorfield');
63+ if (!$focus_field) {
64+ $focus_field = $field_error;
65+ }
66+ }
67+ }
68 if($focus_field) {
69 $focus_field.focus();
70 }
71
72=== modified file 'addons/openerp/utils/utils.py'
73--- addons/openerp/utils/utils.py 2018-09-18 12:23:25 +0000
74+++ addons/openerp/utils/utils.py 2021-04-15 08:08:39 +0000
75@@ -378,7 +378,7 @@
76 if rounding_value in attrs.get('uom_rounding'):
77 rounding = int(abs(math.log10(attrs['uom_rounding'][rounding_value])))
78
79- v = validators.Float(digit=attrs.get("digit"), computation=attrs.get("computation"), rounding=rounding)
80+ v = validators.Float(digit=attrs.get("digit"), computation=attrs.get("computation"), rounding=rounding, en_thousand_sep=attrs.get('en_thousand_sep', True))
81
82 v.not_empty = (required or False) and True
83
84
85=== modified file 'addons/openerp/validators.py'
86--- addons/openerp/validators.py 2018-07-30 14:25:14 +0000
87+++ addons/openerp/validators.py 2021-04-15 08:08:39 +0000
88@@ -76,14 +76,22 @@
89 digit = 2
90 computation = False
91 rounding = False
92+ en_thousand_sep = True
93
94 def _from_python(self, value, state):
95 if self.rounding is not False:
96- return format.format_decimal(float(value) or 0.0, self.rounding)
97- return format.format_decimal(float(value) or 0.0, self.digit, computation=self.computation)
98+ ret_value = format.format_decimal(float(value) or 0.0, self.rounding)
99+ else:
100+ ret_value = format.format_decimal(float(value) or 0.0, self.digit, computation=self.computation)
101+
102+ if ret_value and self.en_thousand_sep == 'False':
103+ ret_value = ret_value.replace(',', '')
104+ return ret_value
105
106 def _to_python(self, value, state):
107 try:
108+ if self.en_thousand_sep=='False' and value and ',' in value:
109+ raise ValueError
110 value = format.parse_decimal(value)
111 except ValueError:
112 raise formencode.api.Invalid(_('Invalid literal for float'), value, state)
113
114=== modified file 'addons/openerp/widgets/form/_form.py'
115--- addons/openerp/widgets/form/_form.py 2020-12-10 14:49:27 +0000
116+++ addons/openerp/widgets/form/_form.py 2021-04-15 08:08:39 +0000
117@@ -463,11 +463,14 @@
118
119 class Float(TinyInputWidget):
120 template = "/openerp/widgets/form/templates/float.mako"
121-
122+ params = ['en_thousand_sep']
123+ en_thousand_sep = True
124 def __init__(self, **attrs):
125 super(Float, self).__init__(**attrs)
126
127 self.with_null = attrs.get('with_null')
128+ if not attrs.get('en_thousand_sep', True):
129+ self.en_thousand_sep = False
130 rounding = False
131 if attrs.get('rounding_value') and attrs.get('uom_rounding'):
132 if isinstance(attrs.get('rounding_value'), (list, tuple)):
133@@ -487,7 +490,7 @@
134 computation = attrs.get('computation', False)
135 if isinstance(computation, basestring):
136 computation = eval(computation)
137- self.validator = validators.Float(digit=digit, computation=computation, rounding=rounding)
138+ self.validator = validators.Float(digit=digit, computation=computation, rounding=rounding, en_thousand_sep=self.en_thousand_sep)
139
140 # if not self.default:
141 # self.default = 0.0
142
143=== modified file 'addons/openerp/widgets/form/templates/float.mako'
144--- addons/openerp/widgets/form/templates/float.mako 2019-04-15 12:09:58 +0000
145+++ addons/openerp/widgets/form/templates/float.mako 2021-04-15 08:08:39 +0000
146@@ -4,7 +4,14 @@
147 kind="${kind}"
148 name='${name}'
149 id ='${name}'
150- value="${value}"
151+ % if not en_thousand_sep:
152+ en_thousand_sep = 'False'
153+ % endif
154+ % if not en_thousand_sep and value:
155+ value="${value.replace(',', '')}"
156+ % else:
157+ value="${value}"
158+ % endif
159 size="1"
160 class="${css_class}"
161 ${py.attrs(attrs, fld_readonly=1 if readonly_before_state else 0)} />

Subscribers

People subscribed via source and target branches