Compare commits

...

1 Commits

Author SHA1 Message Date
robin.keunen aba6202662 [ADD] b_stock_coverage: add effective sale price 4 years ago
  1. 2
      .isort.cfg
  2. 2
      beesdoo_product_usability/views/beesdoo_product.xml
  3. 26
      beesdoo_stock_coverage/models/product_template.py
  4. 2
      beesdoo_stock_coverage/views/product_template_view.xml

2
.isort.cfg

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

2
beesdoo_product_usability/views/beesdoo_product.xml

@ -20,6 +20,8 @@
<field name="stock_coverage"/>
<field name="daily_sales"/>
<field name="range_sales"/>
<field name="list_price"/>
<field name="effective_sale_price"/>
</tree>
</field>
</record>

26
beesdoo_stock_coverage/models/product_template.py

@ -32,6 +32,13 @@ class ProductTemplate(models.Model):
compute="_compute_stock_coverage",
store=True,
)
effective_sale_price = fields.Float(
string="Effective Sale Price",
compute="_compute_stock_coverage",
store=True,
help="SUM (total sale price without vat / sold quantity ) "
"/ count (pos order line)",
)
@api.multi
@api.depends("computation_range", "virtual_available", "active")
@ -39,7 +46,11 @@ class ProductTemplate(models.Model):
query = """
select template.id as product_template_id,
sum(pol.qty) as total_sales,
sum(pol.qty) / template.computation_range as daily_sales
sum(pol.qty) / template.computation_range as daily_sales,
sum(pol.price_subtotal / pol.qty) /
count(pol.id) as effective_sale_price,
sum(pol.price_subtotal_incl / pol.qty) /
count(pol.id) as effective_sale_price_incl
from pos_order_line pol
join pos_order po ON pol.order_id = po.id
join product_product product ON pol.product_id = product.id
@ -50,6 +61,7 @@ class ProductTemplate(models.Model):
and po.date_order
BETWEEN now() - template.computation_range * interval '1 days'
and now()
and pol.qty != 0
and template.id in %(template_ids)s
group by product_template_id
"""
@ -62,11 +74,19 @@ class ProductTemplate(models.Model):
return True
self.env.cr.execute(query, {"template_ids": template_ids})
results = {pid: (qty, avg) for pid, qty, avg in self.env.cr.fetchall()}
results = {
pid: (qty, avg, esp, espi)
for pid, qty, avg, esp, espi in self.env.cr.fetchall()
}
for template in self:
qty, avg = results.get(template.id, (0, 0))
qty, avg, esp, espi = results.get(template.id, (0, 0, 0, 0))
template.range_sales = qty
template.daily_sales = avg
if any(template.taxes_id.mapped("price_include")):
template.effective_sale_price = espi
else:
template.effective_sale_price = esp
if avg != 0:
template.stock_coverage = template.virtual_available / avg
else:

2
beesdoo_stock_coverage/views/product_template_view.xml

@ -12,6 +12,7 @@
<field name="daily_sales"/>
<field name="range_sales"/>
<field name="stock_coverage"/>
<field name="effective_sale_price"/>
</group>
</group>
</field>
@ -26,6 +27,7 @@
<field name="range_sales"/>
<field name="daily_sales"/>
<field name="stock_coverage"/>
<field name="effective_sale_price"/>
</field>
</field>
</record>

Loading…
Cancel
Save