Browse Source

[WIP] beesdoo_purchase: adapt selling price

12.0-beesdoo_purchase-adapt-product-purchase-selling-price
Vincent Van Rossem 4 years ago
parent
commit
699c75bcfc
  1. 35
      beesdoo_purchase/models/purchase.py
  2. 15
      beesdoo_purchase/views/purchase_order.xml

35
beesdoo_purchase/models/purchase.py

@ -57,17 +57,28 @@ class PurchaseOrder(models.Model):
res = super(PurchaseOrder, self).button_confirm() res = super(PurchaseOrder, self).button_confirm()
for order in self: for order in self:
for line in order.order_line: for line in order.order_line:
if line.adapt_purchase_price:
seller = line.product_id._select_seller(
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, partner_id=line.order_id.partner_id,
quantity=line.product_qty, quantity=line.product_qty,
date=order.date_order and order.date_order.date(), date=order.date_order and order.date_order.date(),
uom_id=line.product_uom, uom_id=line.product_uom,
params={'order_id': line.order_id}
params={"order_id": line.order_id},
) )
if seller:
seller.price = line.price_unit
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 return res
@ -76,14 +87,14 @@ class PurchaseOrderLine(models.Model):
adapt_purchase_price = fields.Boolean( adapt_purchase_price = fields.Boolean(
default=False, 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( adapt_selling_price = fields.Boolean(
default=False, 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",
) )

15
beesdoo_purchase/views/purchase_order.xml

@ -7,16 +7,15 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//div[hasclass('oe_button_box')]" position="inside"> <xpath expr="//div[hasclass('oe_button_box')]" position="inside">
<button name="action_toggle_adapt_purchase_price" type="object" <button name="action_toggle_adapt_purchase_price" type="object"
string="Adapt Purchase Price"
string="Toggle Purchase Price"
icon="fa-check-square" icon="fa-check-square"
class="oe_stat_button" class="oe_stat_button"
help="TODO"/>
help="Toggle Purchase Price checkboxes to adapt the purchase price on the product page when confirming Purchase Order"/>
<button name="action_toggle_adapt_selling_price" type="object" <button name="action_toggle_adapt_selling_price" type="object"
string="Toggle To Selling Price"
icon="fa-toggle-on"
string="Toggle Selling Price"
icon="fa-check-square"
class="oe_stat_button" class="oe_stat_button"
attrs="{'invisible': True}"
help="TODO"/>
help="Toggle Selling Price checkboxes to adapt the selling price on the product page when confirming Purchase Order"/>
</xpath> </xpath>
<field name="date_order" position="after"> <field name="date_order" position="after">
<field name="supervisor_id"/> <field name="supervisor_id"/>
@ -28,8 +27,8 @@
</attribute> </attribute>
</field> </field>
<field name="price_subtotal" position="after"> <field name="price_subtotal" position="after">
<field name="adapt_purchase_price" string="To purchase price"/>
<field name="adapt_selling_price" string="To selling price" invisible="True"/>
<field name="adapt_purchase_price" string="Is Purchase Price"/>
<field name="adapt_selling_price" string="Is Selling Price"/>
</field> </field>
</field> </field>
</record> </record>

Loading…
Cancel
Save