diff options
Diffstat (limited to 'indoteknik_custom/models/purchase_order.py')
| -rw-r--r-- | indoteknik_custom/models/purchase_order.py | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index f01c4752..ba98d8d3 100644 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -7,21 +7,23 @@ class PurchaseOrder(models.Model): sale_order_id = fields.Many2one('sale.order', string='Sale Order') def sale_order_sync(self): - if self.sale_order_id: - purchase_orders = self.search(['&', ('sale_order_id', '=', self.sale_order_id.id), ('id', '!=', self.id)]) - products_exception = [] - for purchase_order in purchase_orders: - for order_line in purchase_order.order_line: - products_exception.append(order_line.product_id.id) + if not self.sale_order_id: + return - self.order_line.unlink() - for order_line in self.sale_order_id.order_line: - if order_line.product_id.id and order_line.product_id.id not in products_exception: - values = { - 'order_id': self.id, - 'product_id': order_line.product_id.id, - 'name': order_line.product_id.name, - 'product_qty': order_line.product_qty - } - self.env['purchase.order.line'].sudo().create(values) + purchase_orders = self.search(['&', ('sale_order_id', '=', self.sale_order_id.id), ('id', '!=', self.id)]) + products_exception = [] + for purchase_order in purchase_orders: + for order_line in purchase_order.order_line: + products_exception.append(order_line.product_id.id) + + self.order_line.unlink() + for order_line in self.sale_order_id.order_line: + if order_line.product_id.id and order_line.product_id.id not in products_exception: + values = { + 'order_id': self.id, + 'product_id': order_line.product_id.id, + 'name': order_line.product_id.name, + 'product_qty': order_line.product_qty + } + self.env['purchase.order.line'].sudo().create(values) |
