[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
This commit is contained in:
Darshan Kalola (OpenERP) 2013-11-08 18:44:16 +05:30
parent 50963cc810
commit 412ee4bd8a
3 changed files with 32 additions and 4 deletions

View File

@ -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 = {}

View File

@ -116,7 +116,7 @@ parameter) will see those record just disappear.
-->
<record id="list_price" model="product.price.type">
<field name="name">Public Price</field>
<field name="field">list_price</field>
<field name="field">lst_price</field>
</record>
<record id="standard_price" model="product.price.type">
<field name="name">Cost Price</field>

View File

@ -618,6 +618,18 @@
</record>
<!-- Variants -->
<record id="product_variant_search_form_view" model="ir.ui.view">
<field name="name">product.variant.search.form</field>
<field name="model">product.product</field>
<field name="arch" type="xml">
<search string="Product Variant">
<field name="name" string="Product" filter_domain="['|','|',('name','ilike',self),('default_code','ilike',self),('variants','ilike',self)]"/>
<group expand='0' string='Group by...'>
<filter string='Template' name="template_id" domain="[]" context="{'group_by' : 'product_tmpl_id'}"/>
</group>
</search>
</field>
</record>
<record id="product_variant_form_view" model="ir.ui.view">
<field name="name">product.variant.form</field>
<field name="model">product.product</field>
@ -662,7 +674,7 @@
<field name="view_type">form</field>
<field name="view_mode">tree,form,kanban</field>
<field name="view_id" ref="product_variant_tree_view"/>
<field name="search_view_id" ref="product_search_form_view"/>
<field name="search_view_id" ref="product_variant_search_form_view"/>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to define a new variant of product.