python 2.7 - How to eliminate duplicate products in odoo purchase order product line? -


while creating purchase order, if add same products twice , creates 2 different product lines instead of updating quantities of same product.

please me this.

you can create model inherits purchase.order.line , override create function way:

class purchase_order_line(models.model):     _inherits = 'purchase.order.line'      @api.one     def create(self, vals):         same_line = self.search([('product_id', '=', vals.get('product_id', false)),                                  ('order_id', '=', vals.get('order_id', false))])         if same_line:             total_qty = same_line.product_qty + vals.get('product_qty', 0)             vals.update({                 'product_qty': total_qty,             })             same_line.write(vals)             return same_line         else:             return super(purchase_order_line, self).create(vals) 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -