Browse Source

Merge pull request #173 from beescoop/12.0-fix-create-article

[FIX] b_stock_coverage: compute coverage fails on article creation
pull/172/head
Robin Keunen 4 years ago
committed by GitHub
parent
commit
d038d02e4a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      beesdoo_stock_coverage/models/product_template.py

11
beesdoo_stock_coverage/models/product_template.py

@ -25,7 +25,7 @@ class ProductTemplate(models.Model):
store=True,
)
daily_sales = fields.Float(
string="Daily Sales", compute="_compute_stock_coverage", store=True,
string="Daily Sales", compute="_compute_stock_coverage", store=True
)
stock_coverage = fields.Float(
string="Stock Coverage (days)",
@ -53,7 +53,14 @@ class ProductTemplate(models.Model):
and template.id in %(template_ids)s
group by product_template_id
"""
template_ids = tuple(self.ids) if self.ids else (self._origin.id,)
if self.ids: # on RecordSet
template_ids = tuple(self.ids)
elif self._origin: # on temporary object (on_change)
template_ids = (self._origin.id,)
else: # on temporary object (creation)
return True
self.env.cr.execute(query, {"template_ids": template_ids})
results = {pid: (qty, avg) for pid, qty, avg in self.env.cr.fetchall()}
for template in self:

Loading…
Cancel
Save