From b550fd58f21ebf46d26c4d8991d33f95d46e02b8 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Thu, 30 Jun 2011 11:20:57 +0200 Subject: [PATCH 01/24] [imp] implemented correct behavior for onchange_price and its one2many bzr revid: nicolas.vanhoren@openerp.com-20110630092057-ysv11h7ntrb7j3yi --- addons/account_voucher/account_voucher.py | 25 ++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index b4422cd8051..7761425c94f 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -294,22 +294,24 @@ class account_voucher(osv.osv): return True def onchange_price(self, cr, uid, ids, line_ids, tax_id, partner_id=False, context=None): + context = context or {} tax_pool = self.pool.get('account.tax') partner_pool = self.pool.get('res.partner') position_pool = self.pool.get('account.fiscal.position') + line_pool = self.pool.get('account.voucher.line') res = { 'tax_amount': False, 'amount': False, } voucher_total = 0.0 - voucher_line_ids = [] + + line_ids = resolve_o2m_operations(cr, uid, line_pool, line_ids, ["amount"], context) total = 0.0 total_tax = 0.0 for line in line_ids: line_amount = 0.0 - line_amount = line[2] and line[2].get('amount',0.0) or 0.0 - voucher_line_ids += [line[1]] + line_amount = line.get('amount',0.0) voucher_total += line_amount total = voucher_total @@ -1008,4 +1010,21 @@ class account_bank_statement_line(osv.osv): account_bank_statement_line() +def resolve_o2m_operations(cr, uid, target_osv, operations, fields, context): + results = [] + for operation in operations: + result = None + if not isinstance(operation, (list, tuple)): + result = target_osv.read(cr, uid, operation, fields, context=context) + if operation[0] == 0: + # may be necessary to check if all the fields are here and get the default values? + result = operation[2] + elif operation[0] == 1: + result = target_osv.read(cr, uid, operation[1], fields, context=context) + result.update(operation[2]) + elif operation[0] == 4: + result = target_osv.read(cr, uid, operation[1], fields, context=context) + results.append(result) + return results + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From d40da9c9d6b0de71c96b3f66ae95cdd477b3c053 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Thu, 30 Jun 2011 11:42:13 +0200 Subject: [PATCH 02/24] [fix] small potential error that will never in this case anyway bzr revid: nicolas.vanhoren@openerp.com-20110630094213-oioei7gyxz1rfi50 --- addons/account_voucher/account_voucher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index 7761425c94f..f8816ee3f09 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -1016,7 +1016,7 @@ def resolve_o2m_operations(cr, uid, target_osv, operations, fields, context): result = None if not isinstance(operation, (list, tuple)): result = target_osv.read(cr, uid, operation, fields, context=context) - if operation[0] == 0: + elif operation[0] == 0: # may be necessary to check if all the fields are here and get the default values? result = operation[2] elif operation[0] == 1: From 951e10382be3f3ef8ac71693a8df310a913c5ac2 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Thu, 30 Jun 2011 12:19:04 +0200 Subject: [PATCH 03/24] [imp] changed o2m in customer payment too bzr revid: nicolas.vanhoren@openerp.com-20110630101904-23cwohgh57pzjdjo --- addons/account_voucher/account_voucher.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index f8816ee3f09..fe284213f6e 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -150,11 +150,13 @@ class account_voucher(osv.osv): credit += l['amount'] return abs(amount - abs(credit - debit)) - def onchange_line_ids(self, cr, uid, ids, line_dr_ids, line_cr_ids, amount): + def onchange_line_ids(self, cr, uid, ids, line_dr_ids, line_cr_ids, amount, context=None): + context = context or {} if not line_dr_ids and not line_cr_ids: return {'value':{}} - line_dr_ids = [x[2] for x in line_dr_ids] - line_cr_ids = [x[2] for x in line_cr_ids] + line_osv = self.pool.get("account.voucher.line") + line_dr_ids = resolve_o2m_operations(cr, uid, line_osv, line_dr_ids, ['amount'], context) + line_cr_ids = resolve_o2m_operations(cr, uid, line_osv, line_cr_ids, ['amount'], context) return {'value': {'writeoff_amount': self._compute_writeoff_amount(cr, uid, line_dr_ids, line_cr_ids, amount)}} def _get_writeoff_amount(self, cr, uid, ids, name, args, context=None): @@ -1024,7 +1026,8 @@ def resolve_o2m_operations(cr, uid, target_osv, operations, fields, context): result.update(operation[2]) elif operation[0] == 4: result = target_osv.read(cr, uid, operation[1], fields, context=context) - results.append(result) + if result != None: + results.append(result) return results # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From 4a00aefa4db1cca78cbb937d28f094b6762a28f1 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 1 Jul 2011 17:12:37 +0200 Subject: [PATCH 04/24] [fix] cleaned on_change product_id in sale bzr revid: nicolas.vanhoren@openerp.com-20110701151237-lkmtrp60digfi7f6 --- addons/sale/sale.py | 4 +++- addons/sale/sale_view.xml | 6 +++--- addons/sale_layout/sale_layout_view.xml | 6 +++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/addons/sale/sale.py b/addons/sale/sale.py index 0b436f0dc91..64faca26e77 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -1013,7 +1013,9 @@ class sale_order_line(osv.osv): def product_id_change(self, cr, uid, ids, pricelist, product, qty=0, uom=False, qty_uos=0, uos=False, name='', partner_id=False, - lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False): + lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False, context=None): + context = context or {} + lang = lang or ('lang' in context and context['lang']) if not partner_id: raise osv.except_osv(_('No Customer Defined !'), _('You have to select a customer in the sales form !\nPlease set one customer before choosing a product.')) warning = {} diff --git a/addons/sale/sale_view.xml b/addons/sale/sale_view.xml index 6c444ad174d..14d3046e885 100644 --- a/addons/sale/sale_view.xml +++ b/addons/sale/sale_view.xml @@ -128,12 +128,12 @@ @@ -142,7 +142,7 @@ diff --git a/addons/sale_layout/sale_layout_view.xml b/addons/sale_layout/sale_layout_view.xml index 6dee4ddd62f..4b69a01d919 100644 --- a/addons/sale_layout/sale_layout_view.xml +++ b/addons/sale_layout/sale_layout_view.xml @@ -22,13 +22,13 @@ context="{'partner_id':parent.partner_id,'quantity':product_uom_qty,'pricelist':parent.pricelist_id,'shop':parent.shop_id,'uom':product_uom}" name="product_id" attrs="{'readonly':[('layout_type','!=','article')]}" - on_change="product_id_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,product_uos,name,parent.partner_id, 'lang' in context and context['lang'], True, parent.date_order, product_packaging, parent.fiscal_position)" + on_change="product_id_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,product_uos,name,parent.partner_id, False, True, parent.date_order, product_packaging, parent.fiscal_position, False, context)" select="1"/> From f418321fd434ae7fbc2f8dfe396c58a783709c6d Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 1 Jul 2011 17:13:48 +0200 Subject: [PATCH 05/24] [fix] cleaned on_change product_uom in sale bzr revid: nicolas.vanhoren@openerp.com-20110701151348-gl6aoxrfy97ow80m --- addons/sale/sale.py | 4 +++- addons/sale/sale_view.xml | 2 +- addons/sale_layout/sale_layout_view.xml | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/addons/sale/sale.py b/addons/sale/sale.py index 64faca26e77..fd2dddbe309 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -1148,7 +1148,9 @@ class sale_order_line(osv.osv): def product_uom_change(self, cursor, user, ids, pricelist, product, qty=0, uom=False, qty_uos=0, uos=False, name='', partner_id=False, - lang=False, update_tax=True, date_order=False): + lang=False, update_tax=True, date_order=False, context=None): + context = context or {} + lang = lang or ('lang' in context and context['lang']) res = self.product_id_change(cursor, user, ids, pricelist, product, qty=qty, uom=uom, qty_uos=qty_uos, uos=uos, name=name, partner_id=partner_id, lang=lang, update_tax=update_tax, diff --git a/addons/sale/sale_view.xml b/addons/sale/sale_view.xml index 14d3046e885..28201cfaa76 100644 --- a/addons/sale/sale_view.xml +++ b/addons/sale/sale_view.xml @@ -136,7 +136,7 @@ on_change="product_id_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,product_uos,name,parent.partner_id, False, False, parent.date_order, product_packaging, parent.fiscal_position, True, context)" /> + on_change="product_uom_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,product_uos,name,parent.partner_id, False, False, parent.date_order, context)"/> + on_change="product_uom_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,product_uos,name,parent.partner_id, False, False, parent.date_order, context)"/> Date: Mon, 4 Jul 2011 16:14:10 +0200 Subject: [PATCH 06/24] [fix] changed product_id_change in account.invoice.line bzr revid: nicolas.vanhoren@openerp.com-20110704141410-h7ecesw5aduo0kbd --- addons/account/account_invoice_view.xml | 4 ++-- addons/account/invoice.py | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml index ed45c705674..cd1f41af3dc 100644 --- a/addons/account/account_invoice_view.xml +++ b/addons/account/account_invoice_view.xml @@ -53,7 +53,7 @@
- + @@ -175,7 +175,7 @@ - + diff --git a/addons/account/invoice.py b/addons/account/invoice.py index 8b1b2a0edda..712d000b02e 100644 --- a/addons/account/invoice.py +++ b/addons/account/invoice.py @@ -1312,10 +1312,12 @@ class account_invoice_line(osv.osv): res['arch'] = etree.tostring(doc) return res - def product_id_change(self, cr, uid, ids, product, uom, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, address_invoice_id=False, currency_id=False, context=None): + def product_id_change(self, cr, uid, ids, product, uom, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, address_invoice_id=False, currency_id=False, context=None, company_id=None): if context is None: context = {} - company_id = context.get('company_id',False) + company_id = company_id if company_id != None else context.get('company_id',False) + context = dict(context) + context.update({'company_id': company_id}) if not partner_id: raise osv.except_osv(_('No Partner Defined !'),_("You must first select a partner !") ) if not product: From fa3016fd4e853242a3102203b541d9f44bff2f2d Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 4 Jul 2011 16:16:07 +0200 Subject: [PATCH 07/24] [fix] changed uos_id_change in account.invoice.line bzr revid: nicolas.vanhoren@openerp.com-20110704141607-dj6hkda8yv46pr8y --- addons/account/account_invoice_view.xml | 2 +- addons/account/invoice.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml index cd1f41af3dc..be431c9b2e7 100644 --- a/addons/account/account_invoice_view.xml +++ b/addons/account/account_invoice_view.xml @@ -54,7 +54,7 @@ - + diff --git a/addons/account/invoice.py b/addons/account/invoice.py index 712d000b02e..09e8304340c 100644 --- a/addons/account/invoice.py +++ b/addons/account/invoice.py @@ -1388,7 +1388,12 @@ class account_invoice_line(osv.osv): res_final['value']['price_unit'] = new_price return res_final - def uos_id_change(self, cr, uid, ids, product, uom, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, address_invoice_id=False, currency_id=False, context=None): + def uos_id_change(self, cr, uid, ids, product, uom, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, address_invoice_id=False, currency_id=False, context=None, company_id=None): + if context is None: + context = {} + company_id = company_id if company_id != None else context.get('company_id',False) + context = dict(context) + context.update({'company_id': company_id}) warning = {} res = self.product_id_change(cr, uid, ids, product, uom, qty, name, type, partner_id, fposition_id, price_unit, address_invoice_id, currency_id, context=context) if 'uos_id' in res['value']: From f0f386e748c02b22b925fe6bfbed89734dd3a309 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Thu, 7 Jul 2011 12:37:40 +0200 Subject: [PATCH 08/24] [REM] Removed use of attrs and replaced it with modifiers Warning ! You need server Revision: 3497 revid:vmt@openerp.com-20110705122222-bhim9uft3l3sqee8 bzr revid: fme@openerp.com-20110707103740-4m6vrj18wfi2hacy --- addons/base/controllers/main.py | 31 ---------------------- addons/base/static/src/js/form.js | 21 +++++++-------- addons/base/static/src/js/list-editable.js | 4 ++- addons/base/static/src/js/list.js | 18 ++++++------- addons/base/static/src/xml/base.xml | 2 +- 5 files changed, 23 insertions(+), 53 deletions(-) diff --git a/addons/base/controllers/main.py b/addons/base/controllers/main.py index aa870dfc78f..1179eb37d42 100644 --- a/addons/base/controllers/main.py +++ b/addons/base/controllers/main.py @@ -594,36 +594,6 @@ class View(openerpweb.Controller): return {'result': True} return {'result': False} - def normalize_attrs(self, elem, context): - """ Normalize @attrs, @invisible, @required, @readonly and @states, so - the client only has to deal with @attrs. - - See `the discoveries pad `_ for - the rationale. - - :param elem: the current view node (Python object) - :type elem: xml.etree.ElementTree.Element - :param dict context: evaluation context - """ - # If @attrs is normalized in json by server, the eval should be replaced by simplejson.loads - attrs = openerpweb.ast.literal_eval(elem.get('attrs', '{}')) - if 'states' in elem.attrib: - attrs.setdefault('invisible', [])\ - .append(('state', 'not in', elem.attrib.pop('states').split(','))) - if attrs: - elem.set('attrs', simplejson.dumps(attrs)) - for a in ['invisible', 'readonly', 'required']: - if a in elem.attrib: - # In the XML we trust - avalue = bool(eval(elem.get(a, 'False'), - {'context': context or {}})) - if not avalue: - del elem.attrib[a] - else: - elem.attrib[a] = '1' - if a == 'invisible' and 'attrs' in elem.attrib: - del elem.attrib['attrs'] - def transform_view(self, view_string, session, context=None): # transform nodes on the fly via iterparse, instead of # doing it statically on the parsing result @@ -633,7 +603,6 @@ class View(openerpweb.Controller): if event == "start": if root is None: root = elem - self.normalize_attrs(elem, context) self.parse_domains_and_contexts(elem, session) return root diff --git a/addons/base/static/src/js/form.js b/addons/base/static/src/js/form.js index ad9bd74614d..7071c403b95 100644 --- a/addons/base/static/src/js/form.js +++ b/addons/base/static/src/js/form.js @@ -132,7 +132,7 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormV on_form_changed: function() { for (var w in this.widgets) { w = this.widgets[w]; - w.process_attrs(); + w.process_modifiers(); w.update_dom(); } }, @@ -503,7 +503,7 @@ openerp.base.form.compute_domain = function(expr, fields) { stack.push(!_(val).contains(field)); break; default: - this.log("Unsupported operator in attrs :", op); + this.log("Unsupported operator in modifiers :", op); } } return _.all(stack); @@ -514,7 +514,7 @@ openerp.base.form.Widget = openerp.base.Controller.extend({ init: function(view, node) { this.view = view; this.node = node; - this.attrs = JSON.parse(this.node.attrs.attrs || '{}'); + this.modifiers = JSON.parse(this.node.attrs.modifiers || '{}'); this.type = this.type || node.tag; this.element_name = this.element_name || this.type; this.element_id = [this.view.element_id, this.element_name, this.view.widgets_counter++].join("_"); @@ -527,15 +527,15 @@ openerp.base.form.Widget = openerp.base.Controller.extend({ this.string = this.string || node.attrs.string; this.help = this.help || node.attrs.help; - this.invisible = (node.attrs.invisible == '1'); + this.invisible = this.modifiers['invisible'] === true; }, start: function() { this.$element = $('#' + this.element_id); }, - process_attrs: function() { + process_modifiers: function() { var compute_domain = openerp.base.form.compute_domain; - for (var a in this.attrs) { - this[a] = compute_domain(this.attrs[a], this.view.fields); + for (var a in this.modifiers) { + this[a] = compute_domain(this.modifiers[a], this.view.fields); } }, update_dom: function() { @@ -736,10 +736,9 @@ openerp.base.form.Field = openerp.base.form.Widget.extend({ this.field = view.fields_view.fields[node.attrs.name] || {}; this.string = node.attrs.string || this.field.string; this.help = node.attrs.help || this.field.help; - this.invisible = (this.invisible || this.field.invisible == '1'); - this.nolabel = (this.field.nolabel || node.attrs.nolabel) == '1'; - this.readonly = (this.field.readonly || node.attrs.readonly) == '1'; - this.required = (this.field.required || node.attrs.required) == '1'; + this.nolabel = (this.field.nolabel || node.attrs.nolabel) === '1'; + this.readonly = this.modifiers['readonly'] === true; + this.required = this.modifiers['required'] === true; this.invalid = false; this.touched = false; }, diff --git a/addons/base/static/src/js/list-editable.js b/addons/base/static/src/js/list-editable.js index 8b4b16faf04..a460dfcff41 100644 --- a/addons/base/static/src/js/list-editable.js +++ b/addons/base/static/src/js/list-editable.js @@ -268,10 +268,12 @@ openerp.base.list.editable = function (openerp) { openerp.base.list.form[key] = (form_widgets.get_object(key)).extend({ update_dom: function () { this.$element.children().css('visibility', ''); - if (this.invisible && this.node.attrs.invisible !== '1') { + if (this.invisible) { this.$element.children().css('visibility', 'hidden'); } else { + this.invisible = !!this.modifiers.tree_invisible; this._super(); + this.invisible = false; } } }); diff --git a/addons/base/static/src/js/list.js b/addons/base/static/src/js/list.js index aa3fe3f658b..587d2d6a7b5 100644 --- a/addons/base/static/src/js/list.js +++ b/addons/base/static/src/js/list.js @@ -252,18 +252,18 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi var name = field.attrs.name; var column = _.extend({id: name, tag: field.tag}, field.attrs, fields[name]); - // attrs computer - if (column.attrs) { - var attrs = JSON.parse(column.attrs); - column.attrs_for = function (fields) { + // modifiers computer + if (column.modifiers) { + var modifiers = JSON.parse(column.modifiers); + column.modifiers_for = function (fields) { var result = {}; - for (var attr in attrs) { - result[attr] = domain_computer(attrs[attr], fields); + for (var modifier in modifiers) { + result[modifier] = domain_computer(modifiers[modifier], fields); } return result; }; } else { - column.attrs_for = noop; + column.modifiers_for = noop; } return column; }; @@ -275,10 +275,10 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi if (grouped) { this.columns.unshift({ id: '_group', tag: '', string: "Group", meta: true, - attrs_for: function () { return {}; } + modifiers_for: function () { return {}; } }, { id: '_count', tag: '', string: '#', meta: true, - attrs_for: function () { return {}; } + modifiers_for: function () { return {}; } }); } diff --git a/addons/base/static/src/xml/base.xml b/addons/base/static/src/xml/base.xml index d37e1ddd958..c949a892533 100644 --- a/addons/base/static/src/xml/base.xml +++ b/addons/base/static/src/xml/base.xml @@ -324,7 +324,7 @@ - + From 17fdd718d4fc4dbe44c2a72df6fa52a07ac99f9f Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 7 Jul 2011 14:14:46 +0200 Subject: [PATCH 09/24] [FIX] add simplejson dependency to setup.py following vmt@openerp.com-20110705122222-bhim9uft3l3sqee8 requiring it bzr revid: xmo@openerp.com-20110707121446-3cdarrj7s3rny8ie --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 930b266e66b..e36662b16cc 100755 --- a/setup.py +++ b/setup.py @@ -164,6 +164,7 @@ setup(name = name, 'pyyaml', 'pywebdav', 'feedparser', + 'simplejson >= 2.0', ], extras_require = { 'SSL' : ['pyopenssl'], From 488cb59396513773d605049158f4712f4c7409c1 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Thu, 7 Jul 2011 14:25:42 +0200 Subject: [PATCH 10/24] [FIX] hr_attendance: temporarily comment out conficting demo data To be fixed properly very soon. See LP bug 791087. lp bug: https://launchpad.net/bugs/791087 fixed bzr revid: odo@openerp.com-20110707122542-f7ug2yyq2qn6epbt --- addons/hr_attendance/hr_attendance_demo.xml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/hr_attendance/hr_attendance_demo.xml b/addons/hr_attendance/hr_attendance_demo.xml index 4ea4cdb966c..a1f42eb1004 100644 --- a/addons/hr_attendance/hr_attendance_demo.xml +++ b/addons/hr_attendance/hr_attendance_demo.xml @@ -122,6 +122,10 @@ + From f8c1e9819c9a5c8955f2dca9bb5d686d6a9a555f Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 7 Jul 2011 15:48:43 +0200 Subject: [PATCH 11/24] [IMP] row(s) removal in list views: don't reload the whole list, just drop the relevant (or not relevant anymore) rows lp bug: https://launchpad.net/bugs/805550 fixed bzr revid: xmo@openerp.com-20110707134843-vj1yrmcffsuuc0aa --- addons/base/static/src/js/list.js | 37 ++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/addons/base/static/src/js/list.js b/addons/base/static/src/js/list.js index aa3fe3f658b..111db1f23ed 100644 --- a/addons/base/static/src/js/list.js +++ b/addons/base/static/src/js/list.js @@ -409,9 +409,9 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi $.proxy(this, 'reload_content')); }, /** - * Handles the signal to delete a line from the DOM + * Handles the signal to delete lines from the records list * - * @param {Array} ids the id of the object to delete + * @param {Array} ids the ids of the records to delete */ do_delete: function (ids) { if (!ids.length) { @@ -419,7 +419,7 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi } var self = this; return $.when(this.dataset.unlink(ids)).then(function () { - self.reload_content(); + self.groups.drop_records(ids); }); }, /** @@ -769,6 +769,24 @@ openerp.base.ListView.List = Class.extend( /** @lends openerp.base.ListView.List row_parity: (record_index % 2 === 0) ? 'even' : 'odd', row_index: record_index }); + }, + /** + * Stops displaying the records matching the provided ids. + * + * @param {Array} ids identifiers of the records to remove + */ + drop_records: function (ids) { + var self = this; + _(this.rows).chain() + .map(function (record, index) { + return {index: index, id: record.data.id.value}; + }).filter(function (record) { + return _(ids).contains(record.id); + }).reverse() + .each(function (record) { + self.$current.find('tr:eq(' + record.index + ')').remove(); + self.rows.splice(record.index, 1); + }) } // drag and drop }); @@ -1062,6 +1080,19 @@ openerp.base.ListView.Groups = Class.extend( /** @lends openerp.base.ListView.Gr .map(function (child) { return child.get_records(); }).flatten().value(); + }, + /** + * Stops displaying the records with the linked ids, assumes these records + * were deleted from the DB. + * + * This is the up-signal from the `deleted` event on groups and lists. + * + * @param {Array} ids list of identifier of the records to remove. + */ + drop_records: function (ids) { + _.each(this.children, function (child) { + child.drop_records(ids); + }); } }); }; From aa1ae20796655f1bff7f9720088a7bc6aba94d47 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Thu, 7 Jul 2011 16:16:41 +0200 Subject: [PATCH 12/24] [FIX] Always open action target=current in new tab/window for actions triggered by buttons bzr revid: fme@openerp.com-20110707141641-08ooxxj8qc67ucpg --- addons/base/static/src/js/views.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/base/static/src/js/views.js b/addons/base/static/src/js/views.js index 23cd43c0efd..9ed8886c1e5 100644 --- a/addons/base/static/src/js/views.js +++ b/addons/base/static/src/js/views.js @@ -449,7 +449,8 @@ openerp.base.View = openerp.base.Controller.extend({ search_view : false, views_switcher : false, action_buttons : false, - pager : false + pager : false, + new_window: true }; action_manager.do_action(action, on_closed); if (self.view_manager.is_dialog && action.type != 'ir.actions.act_window_close') { From 17f3714bad8384f42025a9a70ec144901a58d6de Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Thu, 7 Jul 2011 16:19:24 +0200 Subject: [PATCH 13/24] [fix] many problems in selection fields, not handling correctly false value & not compatible with m2o bzr revid: nicolas.vanhoren@openerp.com-20110707141924-xx2ya1d53t2valw5 --- addons/base/static/src/js/form.js | 26 ++++++++++++++++++-------- addons/base/static/src/xml/base.xml | 6 +++--- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/addons/base/static/src/js/form.js b/addons/base/static/src/js/form.js index ad9bd74614d..01b99139e3f 100644 --- a/addons/base/static/src/js/form.js +++ b/addons/base/static/src/js/form.js @@ -1117,28 +1117,38 @@ openerp.base.form.FieldSelection = openerp.base.form.Field.extend({ init: function(view, node) { this._super(view, node); this.template = "FieldSelection"; + this.field_index = []; + var self = this; + var i = 0; + _.each(this.field.selection, function(x) { + self.field_index.push({"ikey": "" + i, "ekey": x[0], "label": x[1]}); + i = i + 1; + }); }, start: function() { this._super.apply(this, arguments); this.$element.find('select').change(this.on_ui_change); }, set_value: function(value) { - this._super.apply(this, arguments); - if (value != null && value !== false) { - this.$element.find('select').val(value); - } else { - this.$element.find('select').val('false'); - } + value = value === null ? false : value; + value = value instanceof Array ? value[0] : value; + this._super(value); + var option = _.detect(this.field_index, function(x) {return x.ekey === value;}); + this.$element.find('select').val(option.ikey); }, set_value_from_ui: function() { - this.value = this.$element.find('select').val(); + var ikey = this.$element.find('select').val(); + var option = _.detect(this.field_index, function(x) {return x.ikey === ikey;}); + this.value = option.ekey; }, update_dom: function() { this._super.apply(this, arguments); this.$element.find('select').attr('disabled', this.readonly); }, validate: function() { - this.invalid = this.required && this.$element.find('select').val() === ""; + var ikey = this.$element.find('select').val(); + var option = _.detect(this.field_index, function(x) {return x.ikey === ikey;}); + this.invalid = this.required && option.ekey === false; }, focus: function() { this.$element.find('select').focus(); diff --git a/addons/base/static/src/xml/base.xml b/addons/base/static/src/xml/base.xml index d37e1ddd958..ce204a0b4ab 100644 --- a/addons/base/static/src/xml/base.xml +++ b/addons/base/static/src/xml/base.xml @@ -517,9 +517,9 @@ t-att-id="widget.element_id + '_field'" t-att-class="'field_' + widget.type" style="width: 100%"> - -