From 36cdac48b73a29524ede316e25b20259bbee84d8 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 3 Jun 2014 11:53:41 +0200 Subject: [PATCH] [IMP] product: move product packaging field from product.product to product.template --- addons/point_of_sale/static/src/js/db.js | 11 ++++++----- addons/point_of_sale/static/src/js/models.js | 13 +++++++------ addons/product/product.py | 7 ++----- addons/product/product_view.xml | 2 +- addons/product_expiry/product_expiry_demo.xml | 8 ++++---- addons/sale_stock/sale_stock.py | 2 +- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/addons/point_of_sale/static/src/js/db.js b/addons/point_of_sale/static/src/js/db.js index b8edc9dd472..1057d774806 100644 --- a/addons/point_of_sale/static/src/js/db.js +++ b/addons/point_of_sale/static/src/js/db.js @@ -29,7 +29,7 @@ function openerp_pos_db(instance, module){ this.category_parent = {}; this.category_search_string = {}; this.packagings_by_id = {}; - this.packagings_by_product_id = {}; + this.packagings_by_product_tmpl_id = {}; this.packagings_by_ean13 = {}; }, /* returns the category object from its id. If you pass a list of id as parameters, you get @@ -130,7 +130,7 @@ function openerp_pos_db(instance, module){ if(product.default_code){ str += '|' + product.default_code; } - var packagings = this.packagings_by_product_id[product.id] || []; + var packagings = this.packagings_by_product_tmpl_id[product.product_tmpl_id] || []; for(var i = 0; i < packagings.length; i++){ str += '|' + packagings[i].ean; } @@ -149,6 +149,7 @@ function openerp_pos_db(instance, module){ if (product.variants){ product.name = product.name+" ("+product.variants+")"; } + product.product_tmpl_id = product.product_tmpl_id[0]; if(!stored_categories[categ_id]){ stored_categories[categ_id] = []; } @@ -186,10 +187,10 @@ function openerp_pos_db(instance, module){ for(var i = 0, len = packagings.length; i < len; i++){ var pack = packagings[i]; this.packagings_by_id[pack.id] = pack; - if(!this.packagings_by_product_id[pack.product_id[0]]){ - this.packagings_by_product_id[pack.product_id[0]] = []; + if(!this.packagings_by_product_tmpl_id[pack.product_tmpl_id[0]]){ + this.packagings_by_product_tmpl_id[pack.product_tmpl_id[0]] = []; } - this.packagings_by_product_id[pack.product_id[0]].push(pack); + this.packagings_by_product_tmpl_id[pack.product_tmpl_id[0]].push(pack); if(pack.ean){ this.packagings_by_ean13[pack.ean] = pack; } diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 0c3c91f2a98..94a23042df6 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -204,18 +204,19 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal self.accounting_precision = precision; console.log("PRECISION",precision); */ - return self.fetch('product.packaging',['ean','product_id']); + return self.fetch('product.packaging',['ean','product_tmpl_id']); }).then(function(packagings){ self.db.add_packagings(packagings); - return self.fetch('pos.category', ['id','name','parent_id','child_id','image']) + return self.fetch('pos.category', ['id','name','parent_id','child_id','image']); }).then(function(categories){ self.db.add_categories(categories); return self.fetch( - 'product.product', + 'product.product', ['name', 'list_price','price','pos_categ_id', 'taxes_id', 'ean13', 'default_code', 'variants', - 'to_weight', 'uom_id', 'uos_id', 'uos_coeff', 'mes_type', 'description_sale', 'description'], + 'to_weight', 'uom_id', 'uos_id', 'uos_coeff', 'mes_type', 'description_sale', 'description', + 'product_tmpl_id'], [['sale_ok','=',true],['available_in_pos','=',true]], {pricelist: self.pricelist.id} // context for price ); @@ -230,7 +231,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal }).then(function(bankstatements){ var journals = []; _.each(bankstatements,function(statement) { - journals.push(statement.journal_id[0]) + journals.push(statement.journal_id[0]); }); self.bankstatements = bankstatements; return self.fetch('account.journal', undefined, [['id','in', journals]]); @@ -238,7 +239,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal self.journals = journals; // associate the bank statements with their journals. - var bankstatements = self.bankstatements + var bankstatements = self.bankstatements; for(var i = 0, ilen = bankstatements.length; i < ilen; i++){ for(var j = 0, jlen = journals.length; j < jlen; j++){ if(bankstatements[i].journal_id[0] === journals[j].id){ diff --git a/addons/product/product.py b/addons/product/product.py index 2369db49d43..fd4e308ba45 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -532,10 +532,8 @@ class product_template(osv.osv): help="Small-sized image of the product. It is automatically "\ "resized as a 64x64px image, with aspect ratio preserved. "\ "Use this field anywhere a small image is required."), - - 'packaging' : fields.one2many('product.packaging', 'product_id', 'Logistical Units', + 'packaging_ids' : fields.one2many('product.packaging', 'product_tmpl_id', 'Logistical Units', help="Gives the different ways to package the same product. This has no impact on the picking order and is mainly used if you use the EDI module."), - 'seller_ids': fields.one2many('product.supplierinfo', 'product_tmpl_id', 'Supplier'), 'seller_delay': fields.related('seller_ids','delay', type='integer', string='Supplier Lead Time', help="This is the average delay in days between the purchase order confirmation and the reception of goods for this product and for the default supplier. It is used by the scheduler to order requests based on reordering delays."), @@ -879,7 +877,6 @@ class product_product(osv.osv): 'active': fields.boolean('Active', help="If unchecked, it will allow you to hide the product without removing it."), 'product_tmpl_id': fields.many2one('product.template', 'Product Template', required=True, ondelete="cascade", select=True), 'ean13': fields.char('EAN13 Barcode', size=13, help="International Article Number used for product identification."), - 'packaging': fields.one2many('product.packaging', 'product_id', 'Packaging', help="Gives the different ways to package the same product. This has no impact on the picking order and is mainly used if you use the EDI module."), 'name_template': fields.related('product_tmpl_id', 'name', string="Template Name", type='char', store={ 'product.template': (_get_name_template_ids, ['name'], 10), 'product.product': (lambda self, cr, uid, ids, c=None: ids, [], 10), @@ -1075,7 +1072,7 @@ class product_packaging(osv.osv): 'ul_container': fields.many2one('product.ul', 'Pallet Logistic Unit'), 'rows' : fields.integer('Number of Layers', required=True, help='The number of layers on a pallet or box'), - 'product_id' : fields.many2one('product.product', 'Product', select=1, ondelete='cascade', required=True), + 'product_tmpl_id' : fields.many2one('product.template', 'Product', select=1, ondelete='cascade', required=True), 'ean' : fields.char('EAN', size=14, help="The EAN code of the package unit."), 'code' : fields.char('Code', help="The code of the transport unit."), 'weight': fields.float('Total Package Weight', diff --git a/addons/product/product_view.xml b/addons/product/product_view.xml index 9b5770a565d..65b75821bab 100644 --- a/addons/product/product_view.xml +++ b/addons/product/product_view.xml @@ -657,7 +657,7 @@
- + diff --git a/addons/product_expiry/product_expiry_demo.xml b/addons/product_expiry/product_expiry_demo.xml index bb5d4ac92de..5c1c2e67ca6 100644 --- a/addons/product_expiry/product_expiry_demo.xml +++ b/addons/product_expiry/product_expiry_demo.xml @@ -26,7 +26,7 @@ 6 4 - + 10 @@ -54,7 +54,7 @@ 6 4 - + 10 @@ -82,7 +82,7 @@ 6 4 - + 10 @@ -110,7 +110,7 @@ 6 4 - + 10 diff --git a/addons/sale_stock/sale_stock.py b/addons/sale_stock/sale_stock.py index 65158582eb0..b3bbd253392 100644 --- a/addons/sale_stock/sale_stock.py +++ b/addons/sale_stock/sale_stock.py @@ -277,7 +277,7 @@ class sale_order_line(osv.osv): warning_msgs = res.get('warning') and res['warning'].get('message', '') or '' products = product_obj.browse(cr, uid, product, context=context) - if not products.packaging: + if not products.packaging_ids: packaging = result['product_packaging'] = False if packaging: