511
order_id = self.pool.get('purchase.order').browse(cr, uid, vals['order_id'], context=context)
512
other_lines = self.search(cr, uid, [('order_id', '=', vals['order_id']), ('product_id', '=', vals['product_id']), ('product_uom', '=', vals['product_uom'])], context=context)
513
price = self.pool.get('product.pricelist').price_get(cr,uid,[order_id.pricelist_id.id],
514
vals['product_id'], vals['product_qty'], order_id.partner_id.id,
515
{'uom': vals['product_uom'], 'date': order_id.date_order})[order_id.pricelist_id.id]
516
if other_lines and (price is False or price == 0.00):
517
price_unit = self.browse(cr, uid, other_lines[0], context=context).price_unit
519
if vals.get('price_unit', 0.00) != price_unit and not vals.get('change_price_manually', False):
520
raise osv.except_osv(_('Error'), _('Please check the box \'Price change manually\' to confirm the change of price before saving line !'))
511
522
vals = self._update_merged_line(cr, uid, False, vals, context=context)
522
533
if isinstance(ids, (int, long)):
536
if not context.get('update_merge', False):
537
for line in self.browse(cr, uid, ids, context=context):
538
if vals.get('price_unit', line.price_unit) != line.price_unit and line.other_line_pb and not vals.get('change_price_manually', line.change_price_manually):
539
raise osv.except_osv(_('Error'), _('Please check the box \'Price change manually\' to confirm the change of price before saving line !'))
525
541
if 'product_id' in vals or 'product_qty' in vals or 'product_uom' in vals or 'price_unit' in vals and not context.get('update_merge'):
526
542
for line_id in ids:
527
543
vals = self._update_merged_line(cr, uid, line_id, vals, context=context)
544
560
return super(purchase_order_line, self).unlink(cr, uid, ids, context=context)
562
def _get_other_line(self, cr, uid, ids, field_name, args, context={}):
564
If other lines exists with the same product/UoM and no price
568
for line in self.browse(cr, uid, ids, context=context):
571
price = self.pool.get('product.pricelist').price_get(cr,uid,[line.order_id.pricelist_id.id],
572
line.product_id.id, line.product_qty, line.order_id.partner_id.id,
573
{'uom': line.product_uom.id, 'date': line.order_id.date_order})[line.order_id.pricelist_id.id]
575
lines = self.search(cr, uid, [('order_id', '=', line.order_id.id), ('product_id', '=', line.product_id.id), ('product_uom', '=', line.product_uom.id)])
576
if lines and (price is False or price == 0.00):
548
582
'parent_line_id': fields.many2one('purchase.order.line', string='Parent line'),
549
583
'merged_id': fields.many2one('purchase.order.merged.line', string='Merged line'),
550
584
'origin': fields.char(size=64, string='Origin'),
553
def price_unit_change(self, cr, uid, ids, product_id, product_uom, product_qty, pricelist, partner_id, date_order, context={}):
585
'other_line_pb': fields.function(_get_other_line, method=True, type='boolean', string='Other lines'),
586
'change_price_manually': fields.boolean(string='Update price manually'),
590
'change_price_manually': lambda *a: False,
591
'other_line_pb': lambda *a: False
594
def price_unit_change(self, cr, uid, ids, price_unit, product_id, product_uom, product_qty, pricelist, partner_id, date_order, context={}):
555
596
Display a warning message on change price unit if there are other lines with the same product and the same uom
570
611
lines = self.search(cr, uid, [('order_id', '=', order_id), ('product_id', '=', product_id), ('product_uom', '=', product_uom)])
571
612
if lines and (price is False or price == 0.00):
613
if price_unit != 0.00:
573
615
'title': 'Other lines updated !',
574
'message': 'Be careful ! If you validate the change of the unit price by clicking on \'Save\' button, other lines with the same product and the same UoM will be updated too !',}
575
res.update({'warning': warning})
616
'message': 'Be careful ! If you validate the change of the unit price by clicking on \'Save\' button, other lines with the same product and the same UoM will be updated too ! \
617
Please check the \'Update price manually\' box to confirm the modification of the price.',}
618
res.update({'warning': warning, 'value': {'other_line_pb': True, 'change_price_manually': False}})