From 699c75bcfcb6bd5c680fa2562eb414b2c4d1ea05 Mon Sep 17 00:00:00 2001 From: Vincent Van Rossem Date: Thu, 1 Oct 2020 14:36:43 +0200 Subject: [PATCH] [WIP] beesdoo_purchase: adapt selling price --- beesdoo_purchase/models/purchase.py | 49 ++++++++++++++--------- beesdoo_purchase/views/purchase_order.xml | 15 ++++--- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/beesdoo_purchase/models/purchase.py b/beesdoo_purchase/models/purchase.py index 3c339e3..0a110f5 100644 --- a/beesdoo_purchase/models/purchase.py +++ b/beesdoo_purchase/models/purchase.py @@ -28,8 +28,8 @@ class PurchaseOrder(models.Model): if "supervisor_id" in vals: new_partner = ( self.env["res.users"] - .browse(vals["supervisor_id"]) - .partner_id.id + .browse(vals["supervisor_id"]) + .partner_id.id ) for rec in self: rec.message_unsubscribe( @@ -57,17 +57,28 @@ class PurchaseOrder(models.Model): res = super(PurchaseOrder, self).button_confirm() for order in self: for line in order.order_line: - if line.adapt_purchase_price: - seller = line.product_id._select_seller( - partner_id=line.order_id.partner_id, - quantity=line.product_qty, - date=order.date_order and order.date_order.date(), - uom_id=line.product_uom, - params={'order_id': line.order_id} - ) - if seller: - seller.price = line.price_unit - + product_id = line.product_id + product_tmpl_id = product_id.product_tmpl_id + seller = product_id._select_seller( + partner_id=line.order_id.partner_id, + quantity=line.product_qty, + date=order.date_order and order.date_order.date(), + uom_id=line.product_uom, + params={"order_id": line.order_id}, + ) + price = line.price_unit + suggested_price = ( + price * product_tmpl_id.uom_po_id.factor + ) * (1 + product_tmpl_id.categ_id.profit_margin / 100) + if line.adapt_purchase_price and line.adapt_selling_price: + seller.price = price + # will asynchronously trigger _compute_cost() + # on `product.template` in `beesdoo_product` + product_tmpl_id.list_price = suggested_price + elif line.adapt_purchase_price: + seller.price = price # see above comment + elif line.adapt_selling_price: + product_tmpl_id.list_price = suggested_price return res @@ -76,14 +87,14 @@ class PurchaseOrderLine(models.Model): adapt_purchase_price = fields.Boolean( default=False, - string='Adapt vendor purchase price', - help='Check this box to adapt the purchase price on the product page when confirming Purchase Order' + string="Adapt vendor purchase price", + help="Check this box to adapt the purchase price " + "on the product page when confirming Purchase Order", ) adapt_selling_price = fields.Boolean( default=False, - string='Adapt product seling price', - help='Check this box to adapt the selling price on the product page when confirming Purchase Order' + string="Adapt product seling price", + help="Check this box to adapt the selling price " + "on the product page when confirming Purchase Order", ) - - diff --git a/beesdoo_purchase/views/purchase_order.xml b/beesdoo_purchase/views/purchase_order.xml index 0f8a289..4124343 100644 --- a/beesdoo_purchase/views/purchase_order.xml +++ b/beesdoo_purchase/views/purchase_order.xml @@ -7,16 +7,15 @@