'message': 'You are moving %.2f products but only %.2f available in this lot.' % (product_qty, prodlot.stock_available or 0.0)
}
return {'warning': warning}
-
+
+ def onchange_quantity(self, cr, uid, ids, product_id, product_qty, product_uom, product_uos):
+ result = {
+ 'product_uos_qty': 0.00
+ }
+
+ if (not product_id) or (product_qty <=0.0):
+ return {'value': result}
+
+ product_obj = self.pool.get('product.product')
+ uos_coeff = product_obj.read(cr, uid, product_id, ['uos_coeff'])
+
+ if product_uos and product_uom and (product_uom != product_uos):
+ result['product_uos_qty'] = product_qty * uos_coeff['uos_coeff']
+ else:
+ result['product_uos_qty'] = product_qty
+
+ return {'value': result}
+
def onchange_product_id(self, cr, uid, ids, prod_id=False, loc_id=False, loc_dest_id=False):
if not prod_id:
return {}
product = self.pool.get('product.product').browse(cr, uid, [prod_id])[0]
+ uos_id = product.uos_id and product.uos_id.id or False
result = {
'name': product.name,
'product_uom': product.uom_id.id,
+ 'product_uos': uos_id,
+ 'product_qty': 1.00,
+ 'product_uos_qty' : self.pool.get('stock.move').onchange_quantity(cr, uid, ids, prod_id, 1.00, product.uom_id.id, uos_id)['value']['product_uos_qty']
}
+
if loc_id:
result['location_id'] = loc_id
if loc_dest_id:
<field name="location_id" select="1" domain="[('usage','=','internal')]"/>
<field name="location_dest_id" select="1" domain="[('usage','=','internal')]"/>
<field colspan="4" context="location=location_id" name="product_id" on_change="onchange_product_id(product_id, location_id, location_dest_id)" select="1"/>
- <field name="product_qty" select="1"/>
+ <field name="product_qty" select="1" on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos)"/>
<field name="product_uom" select="1"/>
- <field groups="product.group_uos" name="product_uos"/>
+ <field groups="product.group_uos" name="product_uos" on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos)"/>
<field groups="product.group_uos" name="product_uos_qty"/>
<field colspan="4" invisible="1" name="name" select="1"/>
<field invisible="1" name="date"/>
<field name="location_id" select="1" domain="[('usage','=','internal')]"/>
<field name="location_dest_id" select="1" domain="[('usage','<>','view')]"/>
<field colspan="4" context="location=location_id" name="product_id" on_change="onchange_product_id(product_id, location_id, location_dest_id)" select="1"/>
- <field name="product_qty" select="1"/>
+ <field name="product_qty" select="1" on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos)"/>
<field name="product_uom" select="1"/>
- <field groups="product.group_uos" name="product_uos"/>
+ <field groups="product.group_uos" name="product_uos" on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos)"/>
<field groups="product.group_uos" name="product_uos_qty"/>
<field colspan="4" invisible="1" name="name" select="1"/>
<field invisible="1" name="date"/>
<field name="location_id" select="1" domain="[('usage','=','internal')]"/>
<field name="location_dest_id" select="1" domain="[('usage','<>','view')]"/>
<field colspan="4" context="location=location_id" name="product_id" on_change="onchange_product_id(product_id, location_id, location_dest_id)" select="1"/>
- <field name="product_qty" select="1"/>
+ <field name="product_qty" select="1" on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos)" />
<field name="product_uom" select="1"/>
- <field groups="product.group_uos" name="product_uos"/>
+ <field groups="product.group_uos" name="product_uos" on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos)"/>
<field groups="product.group_uos" name="product_uos_qty"/>
<field colspan="4" invisible="1" name="name" select="1"/>
<field invisible="1" name="date"/>
<field name="location_id" select="1" domain="[('usage','<>','view')]"/>
<field domain="[('usage','=','internal')]" name="location_dest_id" select="1"/>
<field colspan="4" context="location=location_id" name="product_id" on_change="onchange_product_id(product_id, location_id, location_dest_id)" select="1"/>
- <field name="product_qty" select="1"/>
+ <field name="product_qty" select="1" on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos)"/>
<field name="product_uom" select="1"/>
- <field groups="product.group_uos" name="product_uos"/>
+ <field groups="product.group_uos" name="product_uos" on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos)"/>
<field groups="product.group_uos" name="product_uos_qty"/>
<field colspan="4" invisible="1" name="name" select="1"/>
<field groups="base.group_extended" name="date_planned"/>
<tree color="grey:state=='cancel'" string="Moves">
<field name="name"/>
<field name="product_id"/>
- <field name="product_qty"/>
+ <field name="product_qty" on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos)"/>
<field name="product_uom" string="UOM"/>
<field name="picking_id" select="1"/>
<field name="prodlot_id"/>
<field name="location_id" select="1"/>
<field name="location_dest_id" select="1"/>
<field colspan="4" name="product_id" select="1"/>
- <field name="product_qty" select="2"/>
+ <field name="product_qty" select="2" on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos)"/>
<field name="product_uom" select="2"/>
<field colspan="4" name="name" select="2"/>
<field name="date"/>