diff --git a/purchase_order_category/models/purchase_order.py b/purchase_order_category/models/purchase_order.py index 8cf37763..66583f90 100644 --- a/purchase_order_category/models/purchase_order.py +++ b/purchase_order_category/models/purchase_order.py @@ -1,7 +1,7 @@ # Copyright 2017-2018 Quartile Limited # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). -from odoo import fields, models +from odoo import api, fields, models class PurchaseOrder(models.Model): @@ -11,3 +11,14 @@ class PurchaseOrder(models.Model): "purchase.category", "Purchase Category", ) + + @api.multi + def write(self, vals): + res = super().write(vals) + if "order_line" in vals or "purchase_category_id" in vals: + for order in self: + products = order.order_line.mapped("product_id") + products.write( + {"purchase_category_id": order.purchase_category_id.id} + ) + return res diff --git a/purchase_shop/models/purchase_order.py b/purchase_shop/models/purchase_order.py index 795bed24..cd38f84c 100644 --- a/purchase_shop/models/purchase_order.py +++ b/purchase_shop/models/purchase_order.py @@ -54,3 +54,17 @@ def onchange_shop_id(self): if picking_type_id: self.picking_type_id = picking_type_id return {"domain": {"purchased_by_id": ids}} + + @api.multi + def write(self, vals): + res = super().write(vals) + if "order_line" in vals or "shop_id" in vals or "purchased_by_id" in vals: + for order in self: + products = order.order_line.mapped("product_id") + products.write( + { + "shop_id": order.shop_id.id, + "purchased_by_id": order.purchased_by_id.id, + } + ) + return res