[MERGE] branch of jco with fix of orderpoint computation + small refactoring of action_cancel() of purchase.order

bzr revid: qdp-launchpad@openerp.com-20140423155557-t0gp3akhzb2y85cz
This commit is contained in:
Quentin (OpenERP) 2014-04-23 17:55:57 +02:00
commit 2e7579c54d
4 changed files with 28 additions and 12 deletions

View File

@ -296,9 +296,16 @@ class purchase_order(osv.osv):
def set_order_line_status(self, cr, uid, ids, status, context=None): def set_order_line_status(self, cr, uid, ids, status, context=None):
line = self.pool.get('purchase.order.line') line = self.pool.get('purchase.order.line')
order_line_ids = []
proc_obj = self.pool.get('procurement.order')
for order in self.browse(cr, uid, ids, context=context): for order in self.browse(cr, uid, ids, context=context):
order_line_ids = [order_line.id for order_line in order.order_line] order_line_ids += [po_line.id for po_line in order.order_line]
if order_line_ids:
line.write(cr, uid, order_line_ids, {'state': status}, context=context) line.write(cr, uid, order_line_ids, {'state': status}, context=context)
if order_line_ids and status == 'cancel':
procs = proc_obj.search(cr, uid, [('purchase_line_id', 'in', order_line_ids)], context=context)
if procs:
proc_obj.write(cr, uid, procs, {'state': 'exception'}, context=context)
return True return True
def button_dummy(self, cr, uid, ids, context=None): def button_dummy(self, cr, uid, ids, context=None):
@ -613,10 +620,6 @@ class purchase_order(osv.osv):
return True return True
return False return False
def wkf_action_cancel(self, cr, uid, ids, context=None):
self.write(cr, uid, ids, {'state': 'cancel'})
self.set_order_line_status(cr, uid, ids, 'cancel', context=context)
def action_cancel(self, cr, uid, ids, context=None): def action_cancel(self, cr, uid, ids, context=None):
for purchase in self.browse(cr, uid, ids, context=context): for purchase in self.browse(cr, uid, ids, context=context):
for pick in purchase.picking_ids: for pick in purchase.picking_ids:
@ -630,7 +633,7 @@ class purchase_order(osv.osv):
if inv and inv.state not in ('cancel', 'draft'): if inv and inv.state not in ('cancel', 'draft'):
raise osv.except_osv( raise osv.except_osv(
_('Unable to cancel this purchase order.'), _('Unable to cancel this purchase order.'),
_('You must first cancel all receptions related to this purchase order.')) _('You must first cancel all invoices related to this purchase order.'))
self.pool.get('account.invoice') \ self.pool.get('account.invoice') \
.signal_invoice_cancel(cr, uid, map(attrgetter('id'), purchase.invoice_ids)) .signal_invoice_cancel(cr, uid, map(attrgetter('id'), purchase.invoice_ids))
self.write(cr, uid, ids, {'state': 'cancel'}) self.write(cr, uid, ids, {'state': 'cancel'})
@ -764,6 +767,15 @@ class purchase_order(osv.osv):
def picking_done(self, cr, uid, ids, context=None): def picking_done(self, cr, uid, ids, context=None):
self.write(cr, uid, ids, {'shipped':1,'state':'approved'}, context=context) self.write(cr, uid, ids, {'shipped':1,'state':'approved'}, context=context)
# Do check on related procurements:
proc_obj = self.pool.get("procurement.order")
po_lines = []
for po in self.browse(cr, uid, ids, context=context):
po_lines += [x.id for x in po.order_line]
if po_lines:
procs = proc_obj.search(cr, uid, [('purchase_line_id', 'in', po_lines)], context=context)
if procs:
proc_obj.check(cr, uid, procs, context=context)
self.message_post(cr, uid, ids, body=_("Products received"), context=context) self.message_post(cr, uid, ids, body=_("Products received"), context=context)
return True return True

View File

@ -37,7 +37,7 @@
<field name="name">cancel</field> <field name="name">cancel</field>
<field name="kind">function</field> <field name="kind">function</field>
<field name="flow_stop">True</field> <field name="flow_stop">True</field>
<field name="action">wkf_action_cancel()</field> <field name="action">action_cancel()</field>
</record> </record>
<record id="act_except_invoice" model="workflow.activity"> <record id="act_except_invoice" model="workflow.activity">
<field name="wkf_id" ref="purchase_order"/> <field name="wkf_id" ref="purchase_order"/>

View File

@ -364,8 +364,8 @@ class procurement_order(osv.osv):
if qty <= 0: if qty <= 0:
continue continue
if op.product_id.type not in ('consu'):
qty -= orderpoint_obj.subtract_procurements(cr, uid, op, context=context) qty -= orderpoint_obj.subtract_procurements(cr, uid, op, context=context)
if qty > 0: if qty > 0:
proc_id = procurement_obj.create(cr, uid, proc_id = procurement_obj.create(cr, uid,

View File

@ -3851,12 +3851,16 @@ class stock_warehouse_orderpoint(osv.osv):
'''This function returns quantity of product that needs to be deducted from the orderpoint computed quantity because there's already a procurement created with aim to fulfill it. '''This function returns quantity of product that needs to be deducted from the orderpoint computed quantity because there's already a procurement created with aim to fulfill it.
''' '''
qty = 0 qty = 0
uom_obj = self.pool.get("product.uom")
for procurement in orderpoint.procurement_ids: for procurement in orderpoint.procurement_ids:
if procurement in ('cancel', 'done'): if procurement.state in ('cancel', 'done'):
continue continue
procurement_qty = uom_obj._compute_qty_obj(cr, uid, procurement.product_uom, procurement.product_qty, procurement.product_id.uom_id, context=context)
for move in procurement.move_ids: for move in procurement.move_ids:
if move.state not in ('draft', 'cancel'): if move.state not in ('draft', 'cancel'):
qty += move.product_qty #if move is already confirmed, assigned or done, the virtual stock is already taking this into account so it shouldn't be deducted
procurement_qty -= move.product_qty
qty += procurement_qty
return qty return qty
def _check_product_uom(self, cr, uid, ids, context=None): def _check_product_uom(self, cr, uid, ids, context=None):
@ -3891,7 +3895,7 @@ class stock_warehouse_orderpoint(osv.osv):
'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse', required=True, ondelete="cascade"), 'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse', required=True, ondelete="cascade"),
'location_id': fields.many2one('stock.location', 'Location', required=True, ondelete="cascade"), 'location_id': fields.many2one('stock.location', 'Location', required=True, ondelete="cascade"),
'product_id': fields.many2one('product.product', 'Product', required=True, ondelete='cascade', domain=[('type', '=', 'product')]), 'product_id': fields.many2one('product.product', 'Product', required=True, ondelete='cascade', domain=[('type', '=', 'product')]),
'product_uom': fields.many2one('product.uom', 'Product Unit of Measure', required=True), 'product_uom': fields.related('product_id', 'uom_id', type='many2one', relation='product.uom', string='Product Unit of Measure', readonly=True, required=True),
'product_min_qty': fields.float('Minimum Quantity', required=True, 'product_min_qty': fields.float('Minimum Quantity', required=True,
help="When the virtual stock goes below the Min Quantity specified for this field, OpenERP generates "\ help="When the virtual stock goes below the Min Quantity specified for this field, OpenERP generates "\
"a procurement to bring the forecasted quantity to the Max Quantity."), "a procurement to bring the forecasted quantity to the Max Quantity."),