[FIX] product, purchase: price computation based on supplier tab of product (and uom computation) + added some warnings if user selection is not compliant with these info
lp bug: https://launchpad.net/bugs/423124 fixed bzr revid: qdp-launchpad@tinyerp.com-20101221125638-4hj2b2z01oh4uorx
This commit is contained in:
parent
5a0a79f5d5
commit
02b60a7382
|
@ -225,7 +225,7 @@ class product_pricelist(osv.osv):
|
|||
'ORDER BY sequence',
|
||||
(tmpl_id, product_id, pricelist_id, qty))
|
||||
res1 = cr.dictfetchall()
|
||||
|
||||
uom_price_already_computed = False
|
||||
for res in res1:
|
||||
if res:
|
||||
if res['base'] == -1:
|
||||
|
@ -246,11 +246,17 @@ class product_pricelist(osv.osv):
|
|||
[('product_id', '=', tmpl_id)] + where)
|
||||
price = 0.0
|
||||
if sinfo:
|
||||
qty_in_product_uom = qty
|
||||
product_default_uom = product_obj.read(cr, uid, [tmpl_id], ['uom_id'])[0]['uom_id'][0]
|
||||
seller_uom = supplierinfo_obj.read(cr, uid, sinfo, ['product_uom'])[0]['product_uom'][0]
|
||||
if seller_uom and product_default_uom and product_default_uom != seller_uom:
|
||||
uom_price_already_computed = True
|
||||
qty_in_product_uom = product_uom_obj._compute_qty(cr, uid, product_default_uom, qty, to_uom_id=seller_uom)
|
||||
cr.execute('SELECT * ' \
|
||||
'FROM pricelist_partnerinfo ' \
|
||||
'WHERE suppinfo_id IN %s' \
|
||||
'AND min_quantity <= %s ' \
|
||||
'ORDER BY min_quantity DESC LIMIT 1', (tuple(sinfo),qty,))
|
||||
'ORDER BY min_quantity DESC LIMIT 1', (tuple(sinfo),qty_in_product_uom,))
|
||||
res2 = cr.dictfetchone()
|
||||
if res2:
|
||||
price = res2['price']
|
||||
|
@ -279,7 +285,7 @@ class product_pricelist(osv.osv):
|
|||
price = False
|
||||
|
||||
if price:
|
||||
if 'uom' in context:
|
||||
if 'uom' in context and not uom_price_already_computed:
|
||||
product = products_dict[product_id]
|
||||
uom = product.uos_id or product.uom_id
|
||||
price = self.pool.get('product.uom')._compute_price(cr, uid, uom.id, price, context['uom'])
|
||||
|
|
|
@ -649,6 +649,7 @@ class purchase_order_line(osv.osv):
|
|||
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':[]}}
|
||||
res = {}
|
||||
prod= self.pool.get('product.product').browse(cr, uid, product)
|
||||
|
||||
product_uom_pool = self.pool.get('product.uom')
|
||||
|
@ -668,32 +669,31 @@ class purchase_order_line(osv.osv):
|
|||
seller_delay = 0
|
||||
|
||||
prod_name = self.pool.get('product.product').name_get(cr, uid, [prod.id], context=context)[0][1]
|
||||
|
||||
res = {}
|
||||
for s in prod.seller_ids:
|
||||
if s.name.id == partner_id:
|
||||
seller_delay = s.delay
|
||||
temp_qty = s.min_qty # supplier _qty assigned to temp
|
||||
if s.product_uom:
|
||||
qty = product_uom_pool._compute_qty(cr, uid, s.product_uom.id, s.min_qty, to_uom_id=prod_uom_po)
|
||||
uom = prod_uom_po
|
||||
temp_qty = product_uom_pool._compute_qty(cr, uid, s.product_uom.id, s.min_qty, to_uom_id=prod.uom_id.id)
|
||||
uom = s.product_uom.id #prod_uom_po
|
||||
temp_qty = s.min_qty # supplier _qty assigned to temp
|
||||
if qty < temp_qty: # If the supplier quantity is greater than entered from user, set minimal.
|
||||
qty = temp_qty
|
||||
if price_unit:
|
||||
price = price_unit
|
||||
else:
|
||||
price = self.pool.get('product.pricelist').price_get(cr,uid,[pricelist],
|
||||
product, 1.0, partner_id, {
|
||||
'uom': prod_uom_po,
|
||||
res.update({'warning': {'title': _('Warning'), 'message': _('The selected supplier has a minimal quantity set to %s, you cannot purchase less.') % qty}})
|
||||
qty_in_product_uom = product_uom_pool._compute_qty(cr, uid, uom, qty, to_uom_id=prod.uom_id.id)
|
||||
price = self.pool.get('product.pricelist').price_get(cr,uid,[pricelist],
|
||||
product, qty_in_product_uom or 1.0, partner_id, {
|
||||
'uom': uom,
|
||||
'date': date_order,
|
||||
})[pricelist]
|
||||
dt = (datetime.now() + relativedelta(days=int(seller_delay) or 0.0)).strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
||||
|
||||
res = {'value': {'price_unit': price, 'name': name or prod_name,
|
||||
res.update({'value': {'price_unit': price, 'name': name or prod_name,
|
||||
'taxes_id':map(lambda x: x.id, prod.supplier_taxes_id),
|
||||
'date_planned': date_planned or dt,'notes': notes or prod.description_purchase,
|
||||
'product_qty': qty,
|
||||
'product_uom': uom}}
|
||||
'product_uom': uom}})
|
||||
domain = {}
|
||||
|
||||
taxes = self.pool.get('account.tax').browse(cr, uid,map(lambda x: x.id, prod.supplier_taxes_id))
|
||||
|
@ -714,6 +714,9 @@ class purchase_order_line(osv.osv):
|
|||
res = self.product_id_change(cr, uid, ids, pricelist, product, qty, uom,
|
||||
partner_id, date_order=date_order,fiscal_position=fiscal_position)
|
||||
if 'product_uom' in res['value']:
|
||||
if uom and uom != res['value']['product_uom']:
|
||||
seller_uom_name = self.pool.get('product.uom').read(cr, uid, [res['value']['product_uom']], ['name'])[0]['name']
|
||||
res.update({'warning': {'title': _('Warning'), 'message': _('The selected supplier only sells this product by %s') % seller_uom_name }})
|
||||
del res['value']['product_uom']
|
||||
if not uom:
|
||||
res['value']['price_unit'] = 0.0
|
||||
|
|
|
@ -282,8 +282,8 @@
|
|||
<form string="Purchase Order Line">
|
||||
<notebook colspan="4">
|
||||
<page string="Order Line">
|
||||
<field colspan="4" context="partner_id=parent.partner_id,quantity=product_qty,pricelist=parent.pricelist_id,uom=product_uom,warehouse=parent.warehouse_id" name="product_id" on_change="product_id_change(parent.pricelist_id,product_id,product_qty,product_uom,parent.partner_id, parent.date_order,parent.fiscal_position,date_planned,name,price_unit,notes)"/>
|
||||
<field context="partner_id=parent.partner_id,quantity=product_qty,pricelist=parent.pricelist_id,uom=product_uom,warehouse=parent.warehouse_id" name="product_qty" on_change="product_id_change(parent.pricelist_id,product_id,product_qty,product_uom,parent.partner_id,parent.date_order,parent.fiscal_position,date_planned,name,price_unit,notes)"/>
|
||||
<field name="product_id" colspan="4" context="partner_id=parent.partner_id,quantity=product_qty,pricelist=parent.pricelist_id,uom=product_uom,warehouse=parent.warehouse_id" on_change="product_id_change(parent.pricelist_id,product_id,product_qty,product_uom,parent.partner_id, parent.date_order,parent.fiscal_position,date_planned,name,price_unit,notes)"/>
|
||||
<field name="product_qty" context="partner_id=parent.partner_id,quantity=product_qty,pricelist=parent.pricelist_id,uom=product_uom,warehouse=parent.warehouse_id" on_change="product_id_change(parent.pricelist_id,product_id,product_qty,product_uom,parent.partner_id,parent.date_order,parent.fiscal_position,date_planned,name,price_unit,notes)"/>
|
||||
<field name="product_uom" on_change="product_uom_change(parent.pricelist_id,product_id,product_qty,product_uom,parent.partner_id, parent.date_order,parent.fiscal_position)"/>
|
||||
<field colspan="4" name="name"/>
|
||||
<field name="date_planned" widget="date"/>
|
||||
|
|
Loading…
Reference in New Issue