diff --git a/stock_demand_estimate/README.rst b/stock_demand_estimate/README.rst index 22e5412f8..89c34993e 100644 --- a/stock_demand_estimate/README.rst +++ b/stock_demand_estimate/README.rst @@ -10,9 +10,9 @@ Stock Demand Estimate .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png :target: https://odoo-community.org/page/development-status :alt: Beta -.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png - :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html - :alt: License: AGPL-3 +.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github :target: https://github.com/OCA/stock-logistics-warehouse/tree/12.0/stock_demand_estimate :alt: OCA/stock-logistics-warehouse @@ -35,27 +35,6 @@ The module does not provide in itself any specific usage of the estimates. .. contents:: :local: -Installation -============ - -This module relies on: - -* The OCA module '2D matrix for x2many fields', and can be downloaded from - Github: https://github.com/OCA/web/tree/12.0/web_widget_x2many_2d_matrix -* The OCA module 'Date Range', and can be downloaded from - Github: https://github.com/OCA/server-ux/tree/12.0/date_range - -Usage -===== - -Go to 'Inventory / Configuration / Date Ranges' and define your estimating periods. - -Go to 'Inventory / Demand Planning / Create Demand Estimates' to create or -update your demand estimates. - -Go to 'Inventory / Demand Planning / Demand Estimates' to review the -estimates created. - Bug Tracker =========== @@ -72,13 +51,13 @@ Credits Authors ~~~~~~~ -* Eficent +* ForgeFlow Contributors ~~~~~~~~~~~~ -* Jordi Ballester Alomar -* Lois Rilo +* Jordi Ballester Alomar +* Lois Rilo Maintainers ~~~~~~~~~~~ diff --git a/stock_demand_estimate/__init__.py b/stock_demand_estimate/__init__.py index e1e144406..0650744f6 100644 --- a/stock_demand_estimate/__init__.py +++ b/stock_demand_estimate/__init__.py @@ -1,4 +1 @@ -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). - from . import models -from . import wizards diff --git a/stock_demand_estimate/__manifest__.py b/stock_demand_estimate/__manifest__.py index da4e4e337..bfdcf100a 100644 --- a/stock_demand_estimate/__manifest__.py +++ b/stock_demand_estimate/__manifest__.py @@ -1,26 +1,20 @@ -# Copyright 2016 Eficent Business and IT Consulting Services S.L. -# (http://www.eficent.com) -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +# Copyright 2016-19 ForgeFlow S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). { "name": "Stock Demand Estimate", "summary": "Allows to create demand estimates.", "version": "12.0.1.0.0", - "author": "Eficent, " - "Odoo Community Association (OCA)", + "author": "ForgeFlow, Odoo Community Association (OCA)", "website": "https://github.com/OCA/stock-logistics-warehouse", "category": "Warehouse Management", "depends": [ "stock", - "web_widget_x2many_2d_matrix", - "date_range", ], "data": [ "security/ir.model.access.csv", "security/stock_security.xml", "views/stock_demand_estimate_view.xml", - "views/date_range.xml", - "wizards/stock_demand_estimate_wizard_view.xml", ], - "license": "AGPL-3", + "license": "LGPL-3", "installable": True, } diff --git a/stock_demand_estimate/models/__init__.py b/stock_demand_estimate/models/__init__.py index 796276209..7600975f0 100644 --- a/stock_demand_estimate/models/__init__.py +++ b/stock_demand_estimate/models/__init__.py @@ -1,4 +1 @@ -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). - from . import stock_demand_estimate -from . import date_range diff --git a/stock_demand_estimate/models/date_range.py b/stock_demand_estimate/models/date_range.py deleted file mode 100644 index 4fd1daba2..000000000 --- a/stock_demand_estimate/models/date_range.py +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright 2016 Eficent Business and IT Consulting Services S.L. -# (http://www.eficent.com) - -from odoo import api, fields, models - - -class DateRange(models.Model): - _inherit = "date.range" - - days = fields.Integer( - string="Days between dates", - compute='_compute_days', - readonly=True, - ) - - @api.multi - @api.depends('date_start', 'date_end') - def _compute_days(self): - for rec in self.filtered(lambda x: x.date_start and x.date_end): - rec.days = abs(( - rec.date_end - - rec.date_start - ).days) + 1 diff --git a/stock_demand_estimate/models/stock_demand_estimate.py b/stock_demand_estimate/models/stock_demand_estimate.py index 068073642..f6ca4fa28 100644 --- a/stock_demand_estimate/models/stock_demand_estimate.py +++ b/stock_demand_estimate/models/stock_demand_estimate.py @@ -1,22 +1,39 @@ -# Copyright 2016 Eficent Business and IT Consulting Services S.L. -# (http://www.eficent.com) +# Copyright 2016-19 ForgeFlow S.L. (https://www.forgeflow.com) # Copyright 2016 Aleph Objects, Inc. (https://www.alephobjects.com/) -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from odoo import api, fields, models, _ from odoo.addons import decimal_precision as dp from odoo.exceptions import UserError +from datetime import timedelta, date + class StockDemandEstimate(models.Model): _name = 'stock.demand.estimate' _description = 'Stock Demand Estimate Line' - date_range_id = fields.Many2one( - comodel_name="date.range", - string="Estimating Period", - required=True, - ondelete='restrict' + date_from = fields.Date( + compute="_compute_dates", + string="From (computed)", + store=True + ) + date_to = fields.Date( + compute="_compute_dates", + string="To (computed)", + store=True, + ) + manual_date_from = fields.Date(string="From") + manual_date_to = fields.Date(string="To") + manual_duration = fields.Integer( + string="Duration", + help="Duration (in days)", + default=1, + ) + duration = fields.Integer( + compute="_compute_dates", + string="Duration (computed))", + store=True, ) product_id = fields.Many2one( comodel_name="product.product", @@ -43,6 +60,7 @@ class StockDemandEstimate(models.Model): digits=0, store=True, help='Quantity in the default UoM of the product', + readonly=True, ) daily_qty = fields.Float( string='Quantity / Day', @@ -58,11 +76,30 @@ class StockDemandEstimate(models.Model): ) @api.multi - @api.depends('product_qty', 'date_range_id.days') + @api.depends( + "manual_duration", "manual_date_from", "manual_date_to", + ) + def _compute_dates(self): + today = date.today() + for rec in self: + rec.date_from = rec.manual_date_from or today + if rec.manual_date_to: + rec.date_to = rec.manual_date_to + rec.duration = (rec.manual_date_to - rec.date_from).days + elif rec.manual_duration: + rec.date_to = rec.date_from + timedelta( + days=rec.manual_duration) + rec.duration = rec.manual_duration + else: + rec.date_to = rec.date_from + timedelta(days=1) + rec.duration = 1 + + @api.multi + @api.depends("product_qty", "duration") def _compute_daily_qty(self): for rec in self: - if rec.date_range_id.days: - rec.daily_qty = rec.product_qty / rec.date_range_id.days + if rec.duration: + rec.daily_qty = rec.product_qty / rec.duration else: rec.daily_qty = 0.0 @@ -74,6 +111,8 @@ class StockDemandEstimate(models.Model): rec.product_qty = rec.product_uom._compute_quantity( rec.product_uom_qty, rec.product_id.uom_id ) + else: + rec.product_qty = rec.product_uom_qty def _inverse_product_quantity(self): raise UserError(_( @@ -87,19 +126,33 @@ class StockDemandEstimate(models.Model): def name_get(self): res = [] for rec in self: - name = "%s - %s - %s" % ( - rec.date_range_id.name, rec.product_id.name, - rec.location_id.name, + name = "%s - %s: %s - %s" % ( + rec.date_from, rec.date_to, + rec.product_id.name, rec.location_id.name, ) res.append((rec.id, name)) return res + @api.onchange("manual_date_to") + def _onchange_manual_date_to(self): + for rec in self: + if rec.manual_date_from: + rec.manual_duration = ( + rec.manual_date_to - rec.manual_date_from).days + + @api.onchange("manual_duration") + def _onchange_manual_duration(self): + for rec in self: + if rec.manual_date_from: + rec.manual_date_to = rec.manual_date_from + timedelta( + days=rec.manual_duration) + @api.model def get_quantity_by_date_range(self, date_start, date_end): """To be used in other modules""" # Check if the dates overlap with the period - period_date_start = self.date_range_id.date_start - period_date_end = self.date_range_id.date_end + period_date_start = self.date_from + period_date_end = self.date_to # We need only the periods that overlap # the dates introduced by the user. diff --git a/stock_demand_estimate/readme/CONTRIBUTORS.rst b/stock_demand_estimate/readme/CONTRIBUTORS.rst index daeadd46d..10be2497b 100644 --- a/stock_demand_estimate/readme/CONTRIBUTORS.rst +++ b/stock_demand_estimate/readme/CONTRIBUTORS.rst @@ -1,2 +1,2 @@ -* Jordi Ballester Alomar -* Lois Rilo +* Jordi Ballester Alomar +* Lois Rilo diff --git a/stock_demand_estimate/readme/INSTALL.rst b/stock_demand_estimate/readme/INSTALL.rst deleted file mode 100644 index 7d7d64dce..000000000 --- a/stock_demand_estimate/readme/INSTALL.rst +++ /dev/null @@ -1,6 +0,0 @@ -This module relies on: - -* The OCA module '2D matrix for x2many fields', and can be downloaded from - Github: https://github.com/OCA/web/tree/12.0/web_widget_x2many_2d_matrix -* The OCA module 'Date Range', and can be downloaded from - Github: https://github.com/OCA/server-ux/tree/12.0/date_range diff --git a/stock_demand_estimate/readme/USAGE.rst b/stock_demand_estimate/readme/USAGE.rst deleted file mode 100644 index dacb48d45..000000000 --- a/stock_demand_estimate/readme/USAGE.rst +++ /dev/null @@ -1,7 +0,0 @@ -Go to 'Inventory / Configuration / Date Ranges' and define your estimating periods. - -Go to 'Inventory / Demand Planning / Create Demand Estimates' to create or -update your demand estimates. - -Go to 'Inventory / Demand Planning / Demand Estimates' to review the -estimates created. diff --git a/stock_demand_estimate/static/description/index.html b/stock_demand_estimate/static/description/index.html index ecd2bd4fc..e143089c2 100644 --- a/stock_demand_estimate/static/description/index.html +++ b/stock_demand_estimate/static/description/index.html @@ -3,7 +3,7 @@ - + Stock Demand Estimate