Fix uos/uom for sale order
- The converion of the price for uos is now right !!! - SO use now the right uom and price to create invoice bzr revid: ced-3790347345db9f85bd6f9e6de2f25aba26aadfc8
This commit is contained in:
parent
5fd3d8dd4f
commit
e73677d374
|
@ -693,6 +693,12 @@ class mrp_procurement(osv.osv):
|
|||
return proc.move_id.product_uos_qty
|
||||
return False
|
||||
|
||||
def _uom_compute_get(self, cr, uid, proc, context={}):
|
||||
if proc.product_id.type=='product':
|
||||
if proc.move_id.product_uos:
|
||||
return proc.move_id.product_uos.id
|
||||
return False
|
||||
|
||||
#
|
||||
# Return the quantity of product shipped/produced/served, wich may be
|
||||
# different from the planned quantity
|
||||
|
@ -704,6 +710,13 @@ class mrp_procurement(osv.osv):
|
|||
result = proc.product_qty
|
||||
return result
|
||||
|
||||
def uom_get(self, cr, uid, id, context=None):
|
||||
proc = self.browse(cr, uid, id, context)
|
||||
result = self._uom_compute_get(cr, uid, proc, context)
|
||||
if not result:
|
||||
result = proc.product_uom.id
|
||||
return result
|
||||
|
||||
def check_produce_service(self, cr, uid, procurement, context=[]):
|
||||
return True
|
||||
|
||||
|
|
|
@ -92,9 +92,9 @@ class product_uom(osv.osv):
|
|||
from_unit, to_unit = uoms[-1], uoms[0]
|
||||
if from_unit.category_id.id <> to_unit.category_id.id:
|
||||
return price
|
||||
amount = price / from_unit.factor
|
||||
amount = price * from_unit.factor
|
||||
if to_uom_id:
|
||||
amount = amount * to_unit.factor
|
||||
amount = amount / to_unit.factor
|
||||
return amount
|
||||
|
||||
product_uom()
|
||||
|
|
|
@ -622,9 +622,22 @@ class sale_order_line(osv.osv):
|
|||
def invoice_line_create(self, cr, uid, ids, context={}):
|
||||
def _get_line_qty(line):
|
||||
if (line.order_id.invoice_quantity=='order') or not line.procurement_id:
|
||||
return line.product_uos_qty or line.product_uom_qty
|
||||
if line.product_uos:
|
||||
return line.product_uos_qty or 0.0
|
||||
return line.product_uom_qty
|
||||
else:
|
||||
return self.pool.get('mrp.procurement').quantity_get(cr, uid, line.procurement_id.id, context)
|
||||
return self.pool.get('mrp.procurement').quantity_get(cr, uid,
|
||||
line.procurement_id.id, context)
|
||||
|
||||
def _get_line_uom(line):
|
||||
if (line.order_id.invoice_quantity=='order') or not line.procurement_id:
|
||||
if line.product_uos:
|
||||
return line.product_uos.id
|
||||
return line.product_uom.id
|
||||
else:
|
||||
return self.pool.get('mrp.procurement').uom_get(cr, uid,
|
||||
line.procurement_id.id, context)
|
||||
|
||||
create_ids = []
|
||||
for line in self.browse(cr, uid, ids, context):
|
||||
if not line.invoiced:
|
||||
|
@ -633,14 +646,20 @@ class sale_order_line(osv.osv):
|
|||
if not a:
|
||||
a = line.product_id.categ_id.property_account_income_categ.id
|
||||
if not a:
|
||||
raise osv.except_osv('Error !', 'There is no income account defined for this product: "%s" (id:%d)' % (line.product_id.name, line.product_id.id,))
|
||||
raise osv.except_osv('Error !',
|
||||
'There is no income account defined ' \
|
||||
'for this product: "%s" (id:%d)' % \
|
||||
(line.product_id.name, line.product_id.id,))
|
||||
else:
|
||||
a = self.pool.get('ir.property').get(cr, uid, 'property_account_income_categ', 'product.category', context=context)
|
||||
a = self.pool.get('ir.property').get(cr, uid,
|
||||
'property_account_income_categ', 'product.category',
|
||||
context=context)
|
||||
uosqty = _get_line_qty(line)
|
||||
uos_id = (line.product_uos and line.product_uos.id) or line.product_uom.id
|
||||
pu = line.price_unit
|
||||
if line.product_uos_qty:
|
||||
pu = round(pu * line.product_uom_qty / line.product_uos_qty, int(config['price_accuracy']))
|
||||
uos_id = _get_line_uom(line)
|
||||
pu = 0.0
|
||||
if uosqty:
|
||||
pu = round(line.price_unit * line.product_uom_qty / uosqty,
|
||||
int(config['price_accuracy']))
|
||||
inv_id = self.pool.get('account.invoice.line').create(cr, uid, {
|
||||
'name': line.name,
|
||||
'account_id': a,
|
||||
|
|
Loading…
Reference in New Issue