diff --git a/.isort.cfg b/.isort.cfg
index bd8e906..10b08ea 100644
--- a/.isort.cfg
+++ b/.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
diff --git a/beesdoo_product_usability/views/beesdoo_product.xml b/beesdoo_product_usability/views/beesdoo_product.xml
index 42cf18b..ce33a46 100644
--- a/beesdoo_product_usability/views/beesdoo_product.xml
+++ b/beesdoo_product_usability/views/beesdoo_product.xml
@@ -20,6 +20,8 @@
+
+
diff --git a/beesdoo_stock_coverage/models/product_template.py b/beesdoo_stock_coverage/models/product_template.py
index 168ffb8..fbf1f4a 100644
--- a/beesdoo_stock_coverage/models/product_template.py
+++ b/beesdoo_stock_coverage/models/product_template.py
@@ -32,25 +32,37 @@ 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")
def _compute_stock_coverage(self):
query = """
- select template.id as product_template_id,
- sum(pol.qty) as total_sales,
- sum(pol.qty) / template.computation_range as daily_sales
+ select template.id as product_template_id,
+ sum(pol.qty) as total_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
join product_template template
- ON product.product_tmpl_id = template.id
+ ON product.product_tmpl_id = template.id
where po.state in ('done', 'invoiced', 'paid')
and template.active
and po.date_order
BETWEEN now() - template.computation_range * interval '1 days'
and now()
- and template.id in %(template_ids)s
+ 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:
diff --git a/beesdoo_stock_coverage/views/product_template_view.xml b/beesdoo_stock_coverage/views/product_template_view.xml
index 39caf18..aaf5ea0 100644
--- a/beesdoo_stock_coverage/views/product_template_view.xml
+++ b/beesdoo_stock_coverage/views/product_template_view.xml
@@ -12,6 +12,7 @@
+
@@ -26,6 +27,7 @@
+