[FIX][REF] purchase: prevent confirming order if no stockable item
After discussing with jco, we decided to keep it simple and have a coherent behavior between different versions, we then changed the behavior from the one of jbefficient PR at 92adf673f7
.
This commit is contained in:
parent
2cc09e86af
commit
6758b4cfc5
|
@ -149,19 +149,6 @@ class purchase_order(osv.osv):
|
|||
limit=1)
|
||||
return res and res[0] or False
|
||||
|
||||
def _has_non_stockable_item(self, cr, uid, ids, *args):
|
||||
res = dict.fromkeys(ids, False)
|
||||
for order in self.browse(cr, uid, ids):
|
||||
for order_line in order.order_line:
|
||||
if (
|
||||
not order_line.product_id
|
||||
or
|
||||
order_line.product_id
|
||||
and order_line.product_id.type not in ('product', 'consu')
|
||||
):
|
||||
res[order.id] = True
|
||||
return res
|
||||
|
||||
STATE_SELECTION = [
|
||||
('draft', 'Draft PO'),
|
||||
('sent', 'RFQ Sent'),
|
||||
|
@ -237,7 +224,6 @@ class purchase_order(osv.osv):
|
|||
'create_uid': fields.many2one('res.users', 'Responsible'),
|
||||
'company_id': fields.many2one('res.company','Company',required=True,select=1, states={'confirmed':[('readonly',True)], 'approved':[('readonly',True)]}),
|
||||
'journal_id': fields.many2one('account.journal', 'Journal'),
|
||||
'has_non_stockable_item': fields.function(_has_non_stockable_item, method=True, type='boolean', string='Contains a non-stockable item'),
|
||||
}
|
||||
_defaults = {
|
||||
'date_order': fields.date.context_today,
|
||||
|
@ -485,10 +471,10 @@ class purchase_order(osv.osv):
|
|||
for po in self.browse(cr, uid, ids, context=context):
|
||||
if not po.order_line:
|
||||
raise osv.except_osv(_('Error!'),_('You cannot confirm a purchase order without any purchase order line.'))
|
||||
if po.invoice_method == 'picking' and po.has_non_stockable_item is True:
|
||||
if po.invoice_method == 'picking' and not any([l.product_id and l.product_id.type in ('product', 'consu') for l in po.order_line]):
|
||||
raise osv.except_osv(
|
||||
_('Error!'),
|
||||
_("You cannot confirm a purchase order with Invoice Control Method 'Based on incoming shipments' that contains non-stockable items."))
|
||||
_("You cannot confirm a purchase order with Invoice Control Method 'Based on incoming shipments' that doesn't contain any stockable item."))
|
||||
for line in po.order_line:
|
||||
if line.state=='draft':
|
||||
todo.append(line.id)
|
||||
|
|
Loading…
Reference in New Issue