From 412ee4bd8a243e6ccf57354d7d461ebb646cd3fc Mon Sep 17 00:00:00 2001 From: "Darshan Kalola (OpenERP)" Date: Fri, 8 Nov 2013 18:44:16 +0530 Subject: [PATCH 1/2] [IMP]add search view for product-variant,solve duplication problem of product variant and solve unit price calculation problem. bzr revid: dka@tinyerp.com-20131108131416-cyqebxz9zgbjy9nj --- addons/product/product.py | 20 ++++++++++++++++++-- addons/product/product_data.xml | 2 +- addons/product/product_view.xml | 14 +++++++++++++- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/addons/product/product.py b/addons/product/product.py index 2eaf904548d..18b660a11e0 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -799,9 +799,13 @@ class product_product(osv.osv): # will do the other languages). context_wo_lang = context.copy() context_wo_lang.pop('lang', None) - product = self.read(cr, uid, id, ['name', 'list_price', 'standard_price', 'categ_id'], context=context_wo_lang) + product = self.read(cr, uid, id, ['name', 'list_price', 'standard_price', 'categ_id', 'variants', 'product_tmpl_id'], context=context_wo_lang) default = default.copy() - default.update(name=_("%s (copy)") % (product['name']), list_price=product['list_price'], standard_price=product['standard_price'], categ_id=product['categ_id'][0], product_tmpl_id=None) + if product['variants']: + default.update(variants=_("%s (copy)") % (product['variants']), product_tmpl_id=product['product_tmpl_id'][0]) + else: + default.update(name=_("%s (copy)") % (product['name']), list_price=product['list_price'], standard_price=product['standard_price'], categ_id=product['categ_id'][0], product_tmpl_id=None) + if context.get('variant',False): fields = ['product_tmpl_id', 'active', 'variants', 'default_code', 'price_margin', 'price_extra'] @@ -817,6 +821,18 @@ class product_product(osv.osv): return super(product_product, self).copy(cr, uid, id, default=default, context=context) + def copy_translations(self, cr, uid, old_id, new_id, context=None): + """ When we do not copy the template along the variant, + copy_translations sometimes receives 2 identical IDs. + That's because the ORM follows the o2m to copy the translations, + so in that case, it follows 'variant_ids' and for each variant, + it copy the translations. One of the variant is the 'new_id'. + Just skip the identical IDs. + """ + if old_id == new_id: + return + super(product_product, self).copy_translations(cr, uid, old_id, new_id, context=context) + def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False): if context is None: context = {} diff --git a/addons/product/product_data.xml b/addons/product/product_data.xml index 0b0496439c8..cf01956c43f 100644 --- a/addons/product/product_data.xml +++ b/addons/product/product_data.xml @@ -116,7 +116,7 @@ parameter) will see those record just disappear. --> Public Price - list_price + lst_price Cost Price diff --git a/addons/product/product_view.xml b/addons/product/product_view.xml index c3968e9861d..77328d67d4e 100644 --- a/addons/product/product_view.xml +++ b/addons/product/product_view.xml @@ -618,6 +618,18 @@ + + product.variant.search.form + product.product + + + + + + + + + product.variant.form product.product @@ -662,7 +674,7 @@ form tree,form,kanban - +

Click to define a new variant of product. From e97c4924b7e0744ff7ea1cb1c3cc37ceba610146 Mon Sep 17 00:00:00 2001 From: "Darshan Kalola (OpenERP)" Date: Mon, 11 Nov 2013 18:54:18 +0530 Subject: [PATCH 2/2] [IMP]solve yml issue and improve unit price for invoice line. bzr revid: dka@tinyerp.com-20131111132418-aeazzv8dkyaijgne --- addons/account/account_invoice.py | 2 +- addons/product/product.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index 42f3effd6f9..e089d23a6eb 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -1534,7 +1534,7 @@ class account_invoice_line(osv.osv): if type in ('in_invoice', 'in_refund'): result.update( {'price_unit': price_unit or res.standard_price,'invoice_line_tax_id': tax_id} ) else: - result.update({'price_unit': res.list_price, 'invoice_line_tax_id': tax_id}) + result.update({'price_unit': res.lst_price, 'invoice_line_tax_id': tax_id}) result['uos_id'] = uom_id or res.uom_id.id diff --git a/addons/product/product.py b/addons/product/product.py index 18b660a11e0..fa3b65bdcf8 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -772,8 +772,8 @@ class product_product(osv.osv): product_uom_obj = self.pool.get('product.uom') for product in self.browse(cr, uid, ids, context=context): res[product.id] = product[ptype] or 0.0 - if ptype == 'list_price': - res[product.id] = (res[product.id] + ((res[product.id] * (product.price_margin)) / 100)) + \ + if ptype == 'list_price' or ptype == 'lst_price': + res[product.id] = (product.list_price + ((product.list_price * (product.price_margin)) / 100)) + \ product.price_extra if 'uom' in context: uom = product.uom_id or product.uos_id