Browse Source

flake stock coverage

pull/139/head
robinkeunen 6 years ago
committed by robin.keunen
parent
commit
58f92089ad
  1. 1
      stock_coverage/__openerp__.py
  2. 12
      stock_coverage/models/product_template.py
  3. 7
      stock_coverage/tests/test_stock_coverage.py

1
stock_coverage/__openerp__.py

@ -13,6 +13,7 @@ the display range.
'license': 'AGPL-3', 'license': 'AGPL-3',
'depends': [ 'depends': [
'product', 'product',
'purchase',
'point_of_sale', 'point_of_sale',
'stock' 'stock'
], ],

12
stock_coverage/models/product_template.py

@ -13,7 +13,7 @@ class ProductTemplate(models.Model):
) )
calculation_range = fields.Integer( calculation_range = fields.Integer(
'Calculation range (days)', 'Calculation range (days)',
default=365, # todo sensible defaults, 14, 28?
default=14,
) )
average_consumption = fields.Float( average_consumption = fields.Float(
@ -68,9 +68,8 @@ class ProductTemplate(models.Model):
self.env['pos.order.line'] self.env['pos.order.line']
.search([ .search([
('product_id', 'in', products.ids), ('product_id', 'in', products.ids),
('create_date', '>',
fields.Datetime.to_string(pol_date_limit))
])
('create_date', '>', fields.Datetime.to_string(pol_date_limit)) # noqa
])
) )
if order_lines: if order_lines:
@ -116,10 +115,11 @@ class ProductTemplate(models.Model):
BETWEEN date_trunc('day', now()) - calculation_range * interval '1 days' BETWEEN date_trunc('day', now()) - calculation_range * interval '1 days'
and date_trunc('day', now()) and date_trunc('day', now())
group by product_template_id group by product_template_id
"""
""" # noqa
self.env.cr.execute(query) self.env.cr.execute(query)
results = {pid: qty for pid, qty in self.env.cr.fetchall()} results = {pid: qty for pid, qty in self.env.cr.fetchall()}
for product in products: for product in products:
product.total_consumption = results.get(product.id, product.total_consumption)
product.total_consumption = results.get(product.id,
product.total_consumption)

7
stock_coverage/tests/test_stock_coverage.py

@ -1,12 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from collections import namedtuple
from openerp.tests.common import TransactionCase
from openerp.addons.stock.product import product_template as ProductTemplate
from openerp.addons.stock.product import product_product as ProductProduct
import datetime as dt import datetime as dt
# fixme setup tests based on demo data, test on a clean database
from openerp.tests.common import TransactionCase
_datetimes = map( _datetimes = map(
lambda d: d.strftime('%Y-%m-%d %H:%M:%S'), lambda d: d.strftime('%Y-%m-%d %H:%M:%S'),

Loading…
Cancel
Save