Compare commits

...

3 Commits

Author SHA1 Message Date
Vincent Van Rossem 699c75bcfc [WIP] beesdoo_purchase: adapt selling price 4 years ago
Vincent Van Rossem ae7c3cda51 [WIP] beesdoo_purchase: better button in purchase order form 4 years ago
Vincent Van Rossem 34c9f66233 [WIP] beesdoo_purchase: adapt purchase and/or selling price 4 years ago
  1. 2
      .isort.cfg
  2. 59
      beesdoo_purchase/models/purchase.py
  3. 16
      beesdoo_purchase/views/purchase_order.xml

2
.isort.cfg

@ -9,4 +9,4 @@ line_length = 79
known_odoo = odoo known_odoo = odoo
known_odoo_addons = odoo.addons known_odoo_addons = odoo.addons
sections = FUTURE,STDLIB,THIRDPARTY,ODOO,ODOO_ADDONS,FIRSTPARTY,LOCALFOLDER sections = FUTURE,STDLIB,THIRDPARTY,ODOO,ODOO_ADDONS,FIRSTPARTY,LOCALFOLDER
known_third_party = pytz
known_third_party = pytz,setuptools

59
beesdoo_purchase/models/purchase.py

@ -39,3 +39,62 @@ class PurchaseOrder(models.Model):
partner_ids=[new_partner], subtype_ids=[] partner_ids=[new_partner], subtype_ids=[]
) )
return super(PurchaseOrder, self).write(vals) return super(PurchaseOrder, self).write(vals)
@api.multi
def action_toggle_adapt_purchase_price(self):
for order in self:
for line in order.order_line:
line.adapt_purchase_price ^= True
@api.multi
def action_toggle_adapt_selling_price(self):
for order in self:
for line in order.order_line:
line.adapt_selling_price ^= True
@api.multi
def button_confirm(self):
res = super(PurchaseOrder, self).button_confirm()
for order in self:
for line in order.order_line:
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
class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"
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",
)
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",
)

16
beesdoo_purchase/views/purchase_order.xml

@ -5,6 +5,18 @@
<field name="model">purchase.order</field> <field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/> <field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//div[hasclass('oe_button_box')]" position="inside">
<button name="action_toggle_adapt_purchase_price" type="object"
string="Toggle Purchase Price"
icon="fa-check-square"
class="oe_stat_button"
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"
string="Toggle Selling Price"
icon="fa-check-square"
class="oe_stat_button"
help="Toggle Selling Price checkboxes to adapt the selling price on the product page when confirming Purchase Order"/>
</xpath>
<field name="date_order" position="after"> <field name="date_order" position="after">
<field name="supervisor_id"/> <field name="supervisor_id"/>
</field> </field>
@ -14,6 +26,10 @@
('purchase_ok', '=', True) ] ('purchase_ok', '=', True) ]
</attribute> </attribute>
</field> </field>
<field name="price_subtotal" position="after">
<field name="adapt_purchase_price" string="Is Purchase Price"/>
<field name="adapt_selling_price" string="Is Selling Price"/>
</field>
</field> </field>
</record> </record>

Loading…
Cancel
Save