[FIX] super of scheduler / delivery method and phantom boms / average price
[FIX] super of scheduler should have same params + use_new_cursor should be passed to procure orderpoint confirm [IMP] Make sure the delivery works when doing phantom boms [FIX] This should update the average price properly when having multiple moves with the same product [FIX] Average price should take into account the quantities of all variants [FIX] Make sure purchase picking type in other company works [IMP] Views of quants and destination locations of moves
This commit is contained in:
parent
6b9668520c
commit
518b2f6a3f
|
@ -172,11 +172,20 @@ class stock_move(osv.osv):
|
||||||
}
|
}
|
||||||
|
|
||||||
def action_confirm(self, cr, uid, ids, context=None):
|
def action_confirm(self, cr, uid, ids, context=None):
|
||||||
|
"""
|
||||||
|
Pass the carrier to the picking from the sales order
|
||||||
|
(Should also work in case of Phantom BoMs when on explosion the original move is deleted)
|
||||||
|
"""
|
||||||
|
procs_to_check = []
|
||||||
|
for move in self.browse(cr, uid, ids, context=context):
|
||||||
|
if move.procurement_id and move.procurement_id.sale_line_id and move.procurement_id.sale_line_id.order_id.carrier_id:
|
||||||
|
procs_to_check += [move.procurement_id]
|
||||||
res = super(stock_move, self).action_confirm(cr, uid, ids, context=context)
|
res = super(stock_move, self).action_confirm(cr, uid, ids, context=context)
|
||||||
pick_obj = self.pool.get("stock.picking")
|
pick_obj = self.pool.get("stock.picking")
|
||||||
for move in self.browse(cr, uid, ids, context=context):
|
for proc in procs_to_check:
|
||||||
if move.picking_id and move.procurement_id and move.procurement_id.sale_line_id and not move.picking_id.carrier_id :
|
pickings = list(set([x.picking_id.id for x in proc.move_ids if x.picking_id and not x.picking_id.carrier_id]))
|
||||||
pick_obj.write(cr, uid, [move.picking_id.id], {'carrier_id': move.procurement_id.sale_line_id.order_id.carrier_id.id}, context=context)
|
if pickings:
|
||||||
|
pick_obj.write(cr, uid, pickings, {'carrier_id': proc.sale_line_id.order_id.carrier_id.id}, context=context)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -149,7 +149,6 @@ class purchase_order(osv.osv):
|
||||||
return res and res[0] or False
|
return res and res[0] or False
|
||||||
|
|
||||||
def _get_picking_in(self, cr, uid, context=None):
|
def _get_picking_in(self, cr, uid, context=None):
|
||||||
|
|
||||||
obj_data = self.pool.get('ir.model.data')
|
obj_data = self.pool.get('ir.model.data')
|
||||||
type_obj = self.pool.get('stock.picking.type')
|
type_obj = self.pool.get('stock.picking.type')
|
||||||
user_obj = self.pool.get('res.users')
|
user_obj = self.pool.get('res.users')
|
||||||
|
@ -159,9 +158,11 @@ class purchase_order(osv.osv):
|
||||||
type = type_obj.browse(cr, uid, pick_type, context=context)
|
type = type_obj.browse(cr, uid, pick_type, context=context)
|
||||||
if type and type.warehouse_id and type.warehouse_id.company_id.id == company_id:
|
if type and type.warehouse_id and type.warehouse_id.company_id.id == company_id:
|
||||||
return pick_type
|
return pick_type
|
||||||
types = type_obj.search(cr, uid, [('code', '=', 'incoming')], context=context)
|
types = type_obj.search(cr, uid, [('code', '=', 'incoming'), ('warehouse_id.company_id', '=', company_id)], context=context)
|
||||||
if not types:
|
if not types:
|
||||||
raise osv.except_osv(_('Error!'), _("Make sure you have at least an incoming picking type defined"))
|
types = type_obj.search(cr, uid, [('code', '=', 'incoming'), ('warehouse_id', '=', False)], context=context)
|
||||||
|
if not types:
|
||||||
|
raise osv.except_osv(_('Error!'), _("Make sure you have at least an incoming picking type defined"))
|
||||||
return types[0]
|
return types[0]
|
||||||
|
|
||||||
def _get_picking_ids(self, cr, uid, ids, field_names, args, context=None):
|
def _get_picking_ids(self, cr, uid, ids, field_names, args, context=None):
|
||||||
|
|
|
@ -273,7 +273,7 @@ class procurement_order(osv.osv):
|
||||||
@param context: A standard dictionary for contextual values
|
@param context: A standard dictionary for contextual values
|
||||||
@return: Dictionary of values
|
@return: Dictionary of values
|
||||||
'''
|
'''
|
||||||
super(procurement_order, self).run_scheduler(cr, uid, use_new_cursor=use_new_cursor, context=context)
|
super(procurement_order, self).run_scheduler(cr, uid, use_new_cursor=use_new_cursor, company_id=company_id, context=context)
|
||||||
if context is None:
|
if context is None:
|
||||||
context = {}
|
context = {}
|
||||||
try:
|
try:
|
||||||
|
@ -283,7 +283,7 @@ class procurement_order(osv.osv):
|
||||||
move_obj = self.pool.get('stock.move')
|
move_obj = self.pool.get('stock.move')
|
||||||
|
|
||||||
#Minimum stock rules
|
#Minimum stock rules
|
||||||
self._procure_orderpoint_confirm(cr, SUPERUSER_ID, use_new_cursor=False, company_id=company_id, context=context)
|
self._procure_orderpoint_confirm(cr, SUPERUSER_ID, use_new_cursor=use_new_cursor, company_id=company_id, context=context)
|
||||||
|
|
||||||
#Search all confirmed stock_moves and try to assign them
|
#Search all confirmed stock_moves and try to assign them
|
||||||
confirmed_ids = move_obj.search(cr, uid, [('state', '=', 'confirmed')], limit=None, order='priority desc, date_expected asc', context=context)
|
confirmed_ids = move_obj.search(cr, uid, [('state', '=', 'confirmed')], limit=None, order='priority desc, date_expected asc', context=context)
|
||||||
|
|
|
@ -1093,7 +1093,7 @@
|
||||||
</group>
|
</group>
|
||||||
<group string="Locations" groups="stock.group_locations">
|
<group string="Locations" groups="stock.group_locations">
|
||||||
<field name="location_id" domain="[('usage','<>','view')]"/>
|
<field name="location_id" domain="[('usage','<>','view')]"/>
|
||||||
<field name="location_dest_id" domain="[('usage','=','internal')]"/>
|
<field name="location_dest_id" domain="[('usage','<>','view')]"/>
|
||||||
</group>
|
</group>
|
||||||
<group name="quants_grp" string="Reserved Quants" colspan="4" groups="base.group_no_one">
|
<group name="quants_grp" string="Reserved Quants" colspan="4" groups="base.group_no_one">
|
||||||
<field name="reserved_quant_ids"/>
|
<field name="reserved_quant_ids"/>
|
||||||
|
@ -1662,7 +1662,7 @@
|
||||||
<field name="model">stock.quant</field>
|
<field name="model">stock.quant</field>
|
||||||
<field eval="10" name="priority"/>
|
<field eval="10" name="priority"/>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<form string="Quants">
|
<form string="Quants" create="false" edit="false">
|
||||||
<div class="oe_right oe_button_box">
|
<div class="oe_right oe_button_box">
|
||||||
<button name="action_view_quant_history" type="object" string="Quant History"/>
|
<button name="action_view_quant_history" type="object" string="Quant History"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -282,17 +282,25 @@ class stock_move(osv.osv):
|
||||||
|
|
||||||
def product_price_update_before_done(self, cr, uid, ids, context=None):
|
def product_price_update_before_done(self, cr, uid, ids, context=None):
|
||||||
product_obj = self.pool.get('product.product')
|
product_obj = self.pool.get('product.product')
|
||||||
|
tmpl_dict = {}
|
||||||
for move in self.browse(cr, uid, ids, context=context):
|
for move in self.browse(cr, uid, ids, context=context):
|
||||||
#adapt standard price on incomming moves if the product cost_method is 'average'
|
#adapt standard price on incomming moves if the product cost_method is 'average'
|
||||||
if (move.location_id.usage == 'supplier') and (move.product_id.cost_method == 'average'):
|
if (move.location_id.usage == 'supplier') and (move.product_id.cost_method == 'average'):
|
||||||
product = move.product_id
|
product = move.product_id
|
||||||
product_avail = product.qty_available
|
prod_tmpl_id = move.product_id.product_tmpl_id.id
|
||||||
if product.qty_available <= 0:
|
qty_available = move.product_id.product_tmpl_id.qty_available
|
||||||
|
if tmpl_dict.get(prod_tmpl_id):
|
||||||
|
product_avail = qty_available + tmpl_dict[prod_tmpl_id]
|
||||||
|
else:
|
||||||
|
tmpl_dict[prod_tmpl_id] = 0
|
||||||
|
product_avail = qty_available
|
||||||
|
if product_avail <= 0:
|
||||||
new_std_price = move.price_unit
|
new_std_price = move.price_unit
|
||||||
else:
|
else:
|
||||||
# Get the standard price
|
# Get the standard price
|
||||||
amount_unit = product.standard_price
|
amount_unit = product.standard_price
|
||||||
new_std_price = ((amount_unit * product_avail) + (move.price_unit * move.product_qty)) / (product_avail + move.product_qty)
|
new_std_price = ((amount_unit * product_avail) + (move.price_unit * move.product_qty)) / (product_avail + move.product_qty)
|
||||||
|
tmpl_dict[prod_tmpl_id] += move.product_qty
|
||||||
# Write the standard price, as SUPERUSER_ID because a warehouse manager may not have the right to write on products
|
# Write the standard price, as SUPERUSER_ID because a warehouse manager may not have the right to write on products
|
||||||
product_obj.write(cr, SUPERUSER_ID, [product.id], {'standard_price': new_std_price}, context=context)
|
product_obj.write(cr, SUPERUSER_ID, [product.id], {'standard_price': new_std_price}, context=context)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue