Skip to content

Commit

Permalink
[MIG] stock_demand_estimate: Migration to 12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MiquelRForgeFlow committed Mar 20, 2019
1 parent 5ba6d4c commit ac724da
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 61 deletions.
2 changes: 2 additions & 0 deletions oca_dependencies.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
server-ux
web
14 changes: 7 additions & 7 deletions stock_demand_estimate/README.rst
Original file line number Diff line number Diff line change
@@ -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

=====================
Expand All @@ -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
Expand All @@ -35,23 +35,23 @@ 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
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/stock-logistics-warehouse/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
=======

Images
------

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
* Odoo Community Association: `Icon <https://odoo-community.org/logo.png>`_.

Contributors
------------
Expand Down
2 changes: 0 additions & 2 deletions stock_demand_estimate/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion stock_demand_estimate/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 0 additions & 2 deletions stock_demand_estimate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions stock_demand_estimate/models/date_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 3 additions & 5 deletions stock_demand_estimate/models/stock_demand_estimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -99,10 +99,8 @@ def name_get(self):
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.
Expand Down
2 changes: 2 additions & 0 deletions stock_demand_estimate/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Jordi Ballester Alomar <jordi.ballester@eficent.com>
* Lois Rilo <lois.rilo@eficent.com>
4 changes: 4 additions & 0 deletions stock_demand_estimate/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 6 additions & 0 deletions stock_demand_estimate/readme/INSTALL.rst
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions stock_demand_estimate/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 0 additions & 2 deletions stock_demand_estimate/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions stock_demand_estimate/tests/test_stock_demand_estimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def test_demand_estimate(self):
'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([])
Expand All @@ -173,5 +173,5 @@ def test_invalid_dates(self):
'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])],
})
2 changes: 0 additions & 2 deletions stock_demand_estimate/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -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
74 changes: 38 additions & 36 deletions stock_demand_estimate/wizards/stock_demand_estimate_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit ac724da

Please sign in to comment.