Commit 5b58cef4 by François C.

Merge branch 'products_average_sales_params' into 'dev_cooperatic'

Add 2 parameters available in Odoo system parameters for products sale averages

See merge request !8
parents a72bfb41 9ade24a4
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
'name': "La Cagette Products", 'name': "La Cagette Products",
'summary': """ 'summary': """
Retrieve data such as barcode for all available products (too long request with standard API)""", Retrieve data such as barcode for all available products (too long request with standard API),
average sales (for products in purchase order for ex.)
""",
'description': """ 'description': """
...@@ -16,12 +18,13 @@ ...@@ -16,12 +18,13 @@
# Check https://github.com/odoo/odoo/blob/master/openerp/addons/base/module/module_data.xml # Check https://github.com/odoo/odoo/blob/master/openerp/addons/base/module/module_data.xml
# for the full list # for the full list
'category': 'Product', 'category': 'Product',
'version': '0.0.1', 'version': '0.0.2',
# any module necessary for this one to work correctly # any module necessary for this one to work correctly
'depends': ['base', 'product'], 'depends': ['base', 'product'],
# always loaded # always loaded
'data': [ 'data': [
'data/ir_config_parameter_data.xml'
], ],
'installable': True, 'installable': True,
} }
...@@ -114,7 +114,9 @@ class LaCagetteProducts(models.Model): ...@@ -114,7 +114,9 @@ class LaCagetteProducts(models.Model):
@days: list of full period days (except excluded one, such as sundays) @days: list of full period days (except excluded one, such as sundays)
@return : integer days to remove from days number to compute average @return : integer days to remove from days number to compute average
""" """
minimum_significative_consecutive_days = 5 # arbitrary set (TODO ? : set it in odoo parameters) conf = self.env['ir.config_parameter']
minimum_significative_consecutive_days =\
conf.get_param('lacagette_products.nb_of_consecutive_non_sale_days_considered_as_break')
consecutive_found = [] # each serie is added to compute total of them consecutive_found = [] # each serie is added to compute total of them
missing_days = [] missing_days = []
for d in days: for d in days:
...@@ -188,6 +190,8 @@ class LaCagetteProducts(models.Model): ...@@ -188,6 +190,8 @@ class LaCagetteProducts(models.Model):
@params: list of parameters ('ids', 'period', excluded_days) @params: list of parameters ('ids', 'period', excluded_days)
@return: list (with list key or error key) @return: list (with list key or error key)
""" """
conf = self.env['ir.config_parameter']
delta_day = conf.get_param('lacagette_products.nb_past_days_to_compute_sales_average')
res = {} res = {}
if 'ids' in params: if 'ids' in params:
ids = list(filter(lambda x: isinstance(x, int), params['ids'])) ids = list(filter(lambda x: isinstance(x, int), params['ids']))
...@@ -204,7 +208,7 @@ class LaCagetteProducts(models.Model): ...@@ -204,7 +208,7 @@ class LaCagetteProducts(models.Model):
if 'from' in params: if 'from' in params:
dfrom = params['from'] dfrom = params['from']
else: else:
dfrom = today - datetime.timedelta(50) dfrom = today - datetime.timedelta(delta_day)
dfrom = dfrom.strftime("%Y-%m-%d") dfrom = dfrom.strftime("%Y-%m-%d")
try: try:
sql = """ sql = """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment