diff --git a/stock_demand_estimate/README.rst b/stock_demand_estimate/README.rst index 5814c3a6c..4ae5d51bd 100644 --- a/stock_demand_estimate/README.rst +++ b/stock_demand_estimate/README.rst @@ -1,5 +1,5 @@ -.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.png - :target: https://www.gnu.org/licenses/agpl-3.0-standalone.html +.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: https://www.gnu.org/licenses/agpl :alt: License: AGPL-3 ===================== @@ -17,9 +17,9 @@ 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/11.0/web_widget_x2many_2d_matrix + 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/11.0/date_range + Github: https://github.com/OCA/server-ux/tree/12.0/date_range Usage @@ -35,7 +35,7 @@ estimates created. .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/153/11.0 + :target: https://runbot.odoo-community.org/runbot/153/12.0 Bug Tracker =========== @@ -43,7 +43,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, -help us smashing it by providing a detailed and welcomed feedback. +help us smash it by providing detailed and welcomed feedback. Credits ======= @@ -51,7 +51,7 @@ Credits Images ------ -* Odoo Community Association: `Icon `_. +* Odoo Community Association: `Icon `_. Contributors ------------ diff --git a/stock_demand_estimate/__init__.py b/stock_demand_estimate/__init__.py index db2f7970e..e1e144406 100644 --- a/stock_demand_estimate/__init__.py +++ b/stock_demand_estimate/__init__.py @@ -1,5 +1,3 @@ -# 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). from . import models diff --git a/stock_demand_estimate/__manifest__.py b/stock_demand_estimate/__manifest__.py index 6c33f7337..da4e4e337 100644 --- a/stock_demand_estimate/__manifest__.py +++ b/stock_demand_estimate/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Stock Demand Estimate", "summary": "Allows to create demand estimates.", - "version": "11.0.1.2.0", + "version": "12.0.1.0.0", "author": "Eficent, " "Odoo Community Association (OCA)", "website": "https://github.com/OCA/stock-logistics-warehouse", @@ -22,4 +22,5 @@ "wizards/stock_demand_estimate_wizard_view.xml", ], "license": "AGPL-3", + "installable": True, } diff --git a/stock_demand_estimate/models/__init__.py b/stock_demand_estimate/models/__init__.py index 595f15d26..796276209 100644 --- a/stock_demand_estimate/models/__init__.py +++ b/stock_demand_estimate/models/__init__.py @@ -1,5 +1,3 @@ -# 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). from . import stock_demand_estimate diff --git a/stock_demand_estimate/models/date_range.py b/stock_demand_estimate/models/date_range.py index a33594d4a..4fd1daba2 100644 --- a/stock_demand_estimate/models/date_range.py +++ b/stock_demand_estimate/models/date_range.py @@ -18,6 +18,6 @@ class DateRange(models.Model): def _compute_days(self): for rec in self.filtered(lambda x: x.date_start and x.date_end): rec.days = abs(( - fields.Date.from_string(rec.date_end) - - fields.Date.from_string(rec.date_start) + 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 7cf73e526..068073642 100644 --- a/stock_demand_estimate/models/stock_demand_estimate.py +++ b/stock_demand_estimate/models/stock_demand_estimate.py @@ -24,7 +24,7 @@ class StockDemandEstimate(models.Model): required=True, ) product_uom = fields.Many2one( - comodel_name="product.uom", + comodel_name="uom.uom", string="Unit of measure", ) location_id = fields.Many2one( @@ -43,7 +43,6 @@ 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', @@ -99,10 +98,8 @@ class StockDemandEstimate(models.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 = fields.Date.from_string( - self.date_range_id.date_start - ) - period_date_end = fields.Date.from_string(self.date_range_id.date_end) + period_date_start = self.date_range_id.date_start + period_date_end = self.date_range_id.date_end # 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 new file mode 100644 index 000000000..daeadd46d --- /dev/null +++ b/stock_demand_estimate/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Jordi Ballester Alomar +* Lois Rilo diff --git a/stock_demand_estimate/readme/DESCRIPTION.rst b/stock_demand_estimate/readme/DESCRIPTION.rst new file mode 100644 index 000000000..9f8401d71 --- /dev/null +++ b/stock_demand_estimate/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +This module allows to create demand estimates for a given product and +location, on configurable time periods. + +The module does not provide in itself any specific usage of the estimates. diff --git a/stock_demand_estimate/readme/INSTALL.rst b/stock_demand_estimate/readme/INSTALL.rst new file mode 100644 index 000000000..7d7d64dce --- /dev/null +++ b/stock_demand_estimate/readme/INSTALL.rst @@ -0,0 +1,6 @@ +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 new file mode 100644 index 000000000..dacb48d45 --- /dev/null +++ b/stock_demand_estimate/readme/USAGE.rst @@ -0,0 +1,7 @@ +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/security/stock_security.xml b/stock_demand_estimate/security/stock_security.xml index d26124b0f..24d61ad29 100644 --- a/stock_demand_estimate/security/stock_security.xml +++ b/stock_demand_estimate/security/stock_security.xml @@ -1,7 +1,7 @@ - + Stock demand estimate multi-company diff --git a/stock_demand_estimate/tests/__init__.py b/stock_demand_estimate/tests/__init__.py index 216a1ed7a..c8d75c468 100644 --- a/stock_demand_estimate/tests/__init__.py +++ b/stock_demand_estimate/tests/__init__.py @@ -1,5 +1,3 @@ -# Copyright 2017 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). from . import test_stock_demand_estimate diff --git a/stock_demand_estimate/tests/test_stock_demand_estimate.py b/stock_demand_estimate/tests/test_stock_demand_estimate.py index 97d2d362b..26033121e 100644 --- a/stock_demand_estimate/tests/test_stock_demand_estimate.py +++ b/stock_demand_estimate/tests/test_stock_demand_estimate.py @@ -2,6 +2,7 @@ # (http://www.eficent.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from dateutil.rrule import MONTHLY +from odoo import fields from odoo.exceptions import ValidationError from odoo.tests.common import SavepointCase @@ -93,12 +94,12 @@ class TestStockDemandEstimate(SavepointCase): 'There should be 12 lines.', ) self.assertEqual( - sheet.date_start, + fields.Date.to_string(sheet.date_start), '1943-01-01', 'The date start should be 1943-01-01', ) self.assertEqual( - sheet.date_end, + fields.Date.to_string(sheet.date_end), '1943-12-31', 'The date end should be 1943-12-31', ) @@ -152,7 +153,7 @@ class TestStockDemandEstimate(SavepointCase): 'date_end': '1943-12-31', 'location_id': self.location.id, 'date_range_type_id': self.drt_monthly.id, - 'product_ids': [(6, 0, [self.product1.id])] + 'product_ids': [(6, 0, [self.product1.id])], }) wiz.create_sheet() sheets = self.env['stock.demand.estimate.sheet'].search([]) @@ -173,5 +174,5 @@ class TestStockDemandEstimate(SavepointCase): 'date_end': '1943-01-01', 'location_id': self.location.id, 'date_range_type_id': self.drt_monthly.id, - 'product_ids': [(6, 0, [self.product1.id])] + 'product_ids': [(6, 0, [self.product1.id])], }) diff --git a/stock_demand_estimate/views/date_range.xml b/stock_demand_estimate/views/date_range.xml index c33e48198..dbd9544dc 100644 --- a/stock_demand_estimate/views/date_range.xml +++ b/stock_demand_estimate/views/date_range.xml @@ -1,11 +1,10 @@ - + - \ No newline at end of file + diff --git a/stock_demand_estimate/views/stock_demand_estimate_view.xml b/stock_demand_estimate/views/stock_demand_estimate_view.xml index dcdf7159c..6d6ef7c7c 100644 --- a/stock_demand_estimate/views/stock_demand_estimate_view.xml +++ b/stock_demand_estimate/views/stock_demand_estimate_view.xml @@ -1,8 +1,8 @@ - + stock.demand.estimate.tree stock.demand.estimate @@ -18,7 +18,7 @@ - + stock.demand.estimate.pivot stock.demand.estimate @@ -30,7 +30,7 @@ - stock.demand.estimate.search stock.demand.estimate @@ -43,23 +43,23 @@ - + Stock Demand Estimates ir.actions.act_window stock.demand.estimate form tree,pivot + ref="stock_demand_estimate_view_search"/> - + id="stock_demand_estimate_menu" + parent="stock_demand_planning_menu" + action="stock_demand_estimate_action"/> diff --git a/stock_demand_estimate/wizards/__init__.py b/stock_demand_estimate/wizards/__init__.py index 4dbc3b980..efaf6f4ee 100644 --- a/stock_demand_estimate/wizards/__init__.py +++ b/stock_demand_estimate/wizards/__init__.py @@ -1,5 +1,3 @@ -# 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). from . import stock_demand_estimate_wizard diff --git a/stock_demand_estimate/wizards/stock_demand_estimate_wizard.py b/stock_demand_estimate/wizards/stock_demand_estimate_wizard.py index 76980af0c..cd317b005 100644 --- a/stock_demand_estimate/wizards/stock_demand_estimate_wizard.py +++ b/stock_demand_estimate/wizards/stock_demand_estimate_wizard.py @@ -5,7 +5,7 @@ from odoo import api, fields, models, _ from odoo.osv import expression -import odoo.addons.decimal_precision as dp +from odoo.addons import decimal_precision as dp from odoo.exceptions import UserError, ValidationError @@ -43,39 +43,41 @@ class StockDemandEstimateSheet(models.TransientModel): @api.onchange('date_start', 'date_end', 'date_range_type_id',) def _onchange_dates(self): - if not all([self.date_start, self.date_end, self.date_range_type_id]): - return - ranges = self._get_ranges() - if not ranges: - raise UserError(_('There is no ranges created.')) - estimates = self.env['stock.demand.estimate'].search([ - ('product_id', 'in', self.product_ids.ids), - ('date_range_id', 'in', ranges.ids), - ('location_id', '=', self.location_id.id), - ]) - lines = [] - for product in self.product_ids: - for _range in ranges: - estimate = estimates.filtered( - lambda x: (x.date_range_id == _range and - x.product_id == product) - ) - if estimate: - uom_id = estimate[0].product_uom.id - uom_qty = estimate[0].product_uom_qty - estimate_id = estimate[0].id - else: - uom_id = product.uom_id.id - uom_qty = 0.0 - estimate_id = None - lines.append((0, 0, self._get_default_estimate_line( - _range, - product, - uom_id, - uom_qty, - estimate_id=estimate_id, - ))) - self.line_ids = lines + for sheet in self: + if not all([sheet.date_start, sheet.date_end, + sheet.date_range_type_id]): + return + ranges = sheet._get_ranges() + if not ranges: + raise UserError(_('There is no ranges created.')) + estimates = self.env['stock.demand.estimate'].search([ + ('product_id', 'in', sheet.product_ids.ids), + ('date_range_id', 'in', ranges.ids), + ('location_id', '=', sheet.location_id.id), + ]) + lines = [] + for product in sheet.product_ids: + for _range in ranges: + estimate = estimates.filtered( + lambda x: (x.date_range_id == _range and + x.product_id == product) + ) + if estimate: + uom_id = estimate[0].product_uom.id + uom_qty = estimate[0].product_uom_qty + estimate_id = estimate[0].id + else: + uom_id = product.uom_id.id + uom_qty = 0.0 + estimate_id = None + lines.append((0, 0, sheet._get_default_estimate_line( + _range, + product, + uom_id, + uom_qty, + estimate_id=estimate_id, + ))) + sheet.line_ids = lines def _get_ranges(self): domain_1 = [ @@ -168,10 +170,10 @@ class StockDemandEstimateSheetLine(models.TransientModel): string='Product', ) value_x = fields.Char( - string='Period', + string='Period Name', ) value_y = fields.Char( - string='Product', + string='Product Name', ) product_uom_qty = fields.Float( string="Quantity", diff --git a/stock_demand_estimate/wizards/stock_demand_estimate_wizard_view.xml b/stock_demand_estimate/wizards/stock_demand_estimate_wizard_view.xml index 6a0878045..e08995276 100644 --- a/stock_demand_estimate/wizards/stock_demand_estimate_wizard_view.xml +++ b/stock_demand_estimate/wizards/stock_demand_estimate_wizard_view.xml @@ -1,8 +1,8 @@ - + stock.demand.estimate.sheet.form stock.demand.estimate.sheet @@ -47,8 +47,8 @@ - + stock.demand.estimate.wizard.form stock.demand.estimate.wizard @@ -84,11 +84,10 @@ view_mode="form" target="new" key2="client_action_multi" - id="action_stock_demand_estimate_wizard"/> + id="stock_demand_estimate_wizard_action"/> - +