[FIX] purchase: do not erase description when change quantity

Add a flag to replace or not the previous product description.
Apply the same logic than in sale. Change the description field on a purchase
line only when the product is changed. opw 620093

Clean the views and replace wrong parameter in warning
This commit is contained in:
Martin Trigaux
2015-01-22 15:01:44 +01:00
parent 1c76527ae5
commit 06187405c1
3 changed files with 28 additions and 13 deletions
+8 -7
View File
@@ -1026,7 +1026,7 @@ class purchase_order_line(osv.osv):
context = dict(context, purchase_uom_check=True)
return self.onchange_product_id(cr, uid, ids, pricelist_id, product_id, qty, uom_id,
partner_id, date_order=date_order, fiscal_position_id=fiscal_position_id, date_planned=date_planned,
name=name, price_unit=price_unit, state=state, context=context)
name=name, price_unit=price_unit, state=state, replace=False, context=context)
def _get_date_planned(self, cr, uid, supplier_info, date_order_str, context=None):
"""Return the datetime value to use as Schedule Date (``date_planned``) for
@@ -1058,7 +1058,7 @@ class purchase_order_line(osv.osv):
def onchange_product_id(self, cr, uid, ids, pricelist_id, product_id, qty, uom_id,
partner_id, date_order=False, fiscal_position_id=False, date_planned=False,
name=False, price_unit=False, state='draft', context=None):
name=False, price_unit=False, state='draft', replace=True, context=None):
"""
onchange handler of product_id.
"""
@@ -1088,11 +1088,12 @@ class purchase_order_line(osv.osv):
lang = res_partner.browse(cr, uid, partner_id).lang
context_partner.update( {'lang': lang, 'partner_id': partner_id} )
product = product_product.browse(cr, uid, product_id, context=context_partner)
#call name_get() with partner in the context to eventually match name and description in the seller_ids field
dummy, name = product_product.name_get(cr, uid, product_id, context=context_partner)[0]
if product.description_purchase:
name += '\n' + product.description_purchase
res['value'].update({'name': name})
if replace:
#call name_get() with partner in the context to eventually match name and description in the seller_ids field
dummy, name = product_product.name_get(cr, uid, product_id, context=context_partner)[0]
if product.description_purchase:
name += '\n' + product.description_purchase
res['value'].update({'name': name})
# - set a domain on product_uom
res['domain'] = {'product_uom': [('category_id','=',product.uom_id.category_id.id)]}
+18 -4
View File
@@ -239,12 +239,19 @@
<page string="Products">
<field name="order_line">
<tree string="Purchase Order Lines" editable="bottom">
<field name="product_id" on_change="onchange_product_id(parent.pricelist_id,product_id,0,False,parent.partner_id, parent.date_order,parent.fiscal_position,date_planned,name,False,parent.state,context)" context="{'partner_id': parent.partner_id}"/>
<field name="product_id"
on_change="onchange_product_id(parent.pricelist_id, product_id, 0, False,
parent.partner_id, parent.date_order, parent.fiscal_position, date_planned,
name, False, parent.state, True, context)"
context="{'partner_id': parent.partner_id}"/>
<field name="name"/>
<field name="date_planned"/>
<field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/>
<field name="account_analytic_id" context="{'default_partner_id':parent.partner_id}" groups="purchase.group_analytic_accounting" domain="[('type','not in',('view','template'))]"/>
<field name="product_qty" on_change="onchange_product_id(parent.pricelist_id,product_id,product_qty,product_uom,parent.partner_id,parent.date_order,parent.fiscal_position,date_planned,name,False,parent.state,context)"/>
<field name="product_qty"
on_change="onchange_product_id(parent.pricelist_id, product_id, product_qty,
product_uom, parent.partner_id, parent.date_order, parent.fiscal_position,
date_planned, name, False, parent.state, False, context)"/>
<field name="product_uom" groups="product.group_uom" on_change="onchange_product_uom(parent.pricelist_id,product_id,product_qty,product_uom,parent.partner_id, parent.date_order,parent.fiscal_position,date_planned,name,False,parent.state,context)"/>
<field name="price_unit"/>
<field name="taxes_id" widget="many2many_tags" domain="[('parent_id','=',False),('type_tax_use','!=','sale')]"/>
@@ -422,10 +429,17 @@
<group>
<group>
<field name="product_id"
on_change="onchange_product_id(parent.pricelist_id,product_id,0,False,parent.partner_id, parent.date_order,parent.fiscal_position,date_planned,name,False,context)" context="{'partner_id': parent.partner_id}"/>
on_change="onchange_product_id(parent.pricelist_id, product_id, 0, False,
parent.partner_id, parent.date_order, parent.fiscal_position, date_planned,
name, False, 'draft', True, context)"
context="{'partner_id': parent.partner_id}"/>
<label for="product_qty"/>
<div>
<field name="product_qty" on_change="onchange_product_id(parent.pricelist_id,product_id,product_qty,product_uom,parent.partner_id,parent.date_order,parent.fiscal_position,date_planned,name,False,'draft',context)" class="oe_inline"/>
<field name="product_qty"
on_change="onchange_product_id(parent.pricelist_id, product_id, product_qty,
product_uom, parent.partner_id, parent.date_order, parent.fiscal_position,
date_planned, name, False, 'draft', True, context)"
class="oe_inline"/>
<field name="product_uom" groups="product.group_uom" on_change="onchange_product_uom(parent.pricelist_id,product_id,product_qty,product_uom,parent.partner_id, parent.date_order,parent.fiscal_position,date_planned,name,False,'draft',context)" class="oe_inline"/>
</div>
<field name="price_unit"/>
+2 -2
View File
@@ -237,10 +237,10 @@ class purchase_order_line(osv.osv):
_inherit = 'purchase.order.line'
def onchange_product_id(self,cr, uid, ids, pricelist, product, qty, uom,
partner_id, date_order=False, fiscal_position_id=False, date_planned=False,
name=False, price_unit=False, state='draft', notes=False, context=None):
name=False, price_unit=False, state='draft', replace=True, context=None):
warning = {}
if not product:
return {'value': {'price_unit': price_unit or 0.0, 'name': name or '', 'notes': notes or '', 'product_uom' : uom or False}, 'domain':{'product_uom':[]}}
return {'value': {'price_unit': price_unit or 0.0, 'name': name or '', 'product_uom' : uom or False}, 'domain':{'product_uom':[]}}
product_obj = self.pool.get('product.product')
product_info = product_obj.browse(cr, uid, product)
title = False