From e4d14110ad5e3bfad60f106e8acbb782d9830d7d Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Thu, 3 Sep 2015 12:00:02 +0200 Subject: [PATCH] [ADD] purchase: auto add partner to vendors If a product has no vendor, the partner of the PO will be added as a vendor for the product during the confirmation of the PO. --- addons/purchase/purchase.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index be48ce543df..8a333c13341 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -243,6 +243,22 @@ class PurchaseOrder(models.Model): @api.multi def button_confirm(self): + # Add the partner in the supplier list of the product if no supplier for this product + for line in self.order_line: + if not line.product_id.seller_ids: + supplierinfo = { + 'name': self.partner_id.id, + 'product_uom': line.product_uom.id, + 'min_qty': 0.0, + 'price': line.price_unit, + 'currency_id': self.partner_id.currency_id.id, + 'delay': 0, + } + vals = { + 'seller_ids': [(0, 0, supplierinfo)], + } + line.product_id.write(vals) + # Deal with double validation process if self.user_has_groups('purchase.group_purchase_manager'): return self.button_approve()