mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[MIG] stock_demand_estimate: Migration to 12.0
This commit is contained in:
@@ -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
|
||||
<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
|
||||
=======
|
||||
@@ -51,7 +51,7 @@ 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
|
||||
------------
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
2
stock_demand_estimate/readme/CONTRIBUTORS.rst
Normal file
2
stock_demand_estimate/readme/CONTRIBUTORS.rst
Normal file
@@ -0,0 +1,2 @@
|
||||
* Jordi Ballester Alomar <jordi.ballester@eficent.com>
|
||||
* Lois Rilo <lois.rilo@eficent.com>
|
||||
4
stock_demand_estimate/readme/DESCRIPTION.rst
Normal file
4
stock_demand_estimate/readme/DESCRIPTION.rst
Normal file
@@ -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
stock_demand_estimate/readme/INSTALL.rst
Normal file
6
stock_demand_estimate/readme/INSTALL.rst
Normal file
@@ -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
stock_demand_estimate/readme/USAGE.rst
Normal file
7
stock_demand_estimate/readme/USAGE.rst
Normal file
@@ -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.
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo noupdate="1">
|
||||
|
||||
<record model="ir.rule" id="stock_demand_estimate_comp_rule">
|
||||
<record id="stock_demand_estimate_comp_rule" model="ir.rule">
|
||||
<field name="name">Stock demand estimate multi-company</field>
|
||||
<field name="model_id" ref="model_stock_demand_estimate"/>
|
||||
<field name="global" eval="True"/>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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])],
|
||||
})
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
<?xml version="1.0"?>
|
||||
<odoo>
|
||||
|
||||
<menuitem
|
||||
id="menuitem_date_range"
|
||||
string="Date Ranges"
|
||||
parent="stock.menu_stock_config_settings"
|
||||
action="date_range.date_range_action"
|
||||
sequence="99"/>
|
||||
<menuitem id="date_range_menu"
|
||||
string="Date Ranges"
|
||||
parent="stock.menu_stock_config_settings"
|
||||
action="date_range.date_range_action"
|
||||
sequence="99"/>
|
||||
|
||||
</odoo>
|
||||
</odoo>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0"?>
|
||||
<odoo>
|
||||
|
||||
<record model="ir.ui.view"
|
||||
id="view_stock_demand_estimate_tree">
|
||||
<record id="stock_demand_estimate_view_tree"
|
||||
model="ir.ui.view">
|
||||
<field name="name">stock.demand.estimate.tree</field>
|
||||
<field name="model">stock.demand.estimate</field>
|
||||
<field name="arch" type="xml">
|
||||
@@ -18,7 +18,7 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_stock_demand_estimate_pivot" model="ir.ui.view">
|
||||
<record id="stock_demand_estimate_view_pivot" model="ir.ui.view">
|
||||
<field name="name">stock.demand.estimate.pivot</field>
|
||||
<field name="model">stock.demand.estimate</field>
|
||||
<field name="arch" type="xml">
|
||||
@@ -30,7 +30,7 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_stock_demand_estimate_search"
|
||||
<record id="stock_demand_estimate_view_search"
|
||||
model="ir.ui.view">
|
||||
<field name="name">stock.demand.estimate.search</field>
|
||||
<field name="model">stock.demand.estimate</field>
|
||||
@@ -43,23 +43,23 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.actions.act_window"
|
||||
id="stock_demand_estimate_form_action">
|
||||
<record id="stock_demand_estimate_action"
|
||||
model="ir.actions.act_window">
|
||||
<field name="name">Stock Demand Estimates</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">stock.demand.estimate</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,pivot</field>
|
||||
<field name="search_view_id"
|
||||
ref="view_stock_demand_estimate_search"/>
|
||||
ref="stock_demand_estimate_view_search"/>
|
||||
</record>
|
||||
|
||||
<menuitem id="menu_stock_demand_planning" name="Demand Planning"
|
||||
<menuitem id="stock_demand_planning_menu" name="Demand Planning"
|
||||
parent="stock.menu_stock_root" sequence="10"/>
|
||||
|
||||
<menuitem
|
||||
id="menu_stock_demand_estimate"
|
||||
parent="menu_stock_demand_planning"
|
||||
action="stock_demand_estimate_form_action"/>
|
||||
id="stock_demand_estimate_menu"
|
||||
parent="stock_demand_planning_menu"
|
||||
action="stock_demand_estimate_action"/>
|
||||
|
||||
</odoo>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0"?>
|
||||
<odoo>
|
||||
|
||||
<record model="ir.ui.view"
|
||||
id="view_stock_demand_estimate_sheet_form">
|
||||
<record id="stock_demand_estimate_sheet_view_form"
|
||||
model="ir.ui.view">
|
||||
<field name="name">stock.demand.estimate.sheet.form</field>
|
||||
<field name="model">stock.demand.estimate.sheet</field>
|
||||
<field name="arch" type="xml">
|
||||
@@ -47,8 +47,8 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view"
|
||||
id="view_demand_estimate_wizard_form">
|
||||
<record id="demand_estimate_wizard_view_form"
|
||||
model="ir.ui.view">
|
||||
<field name="name">stock.demand.estimate.wizard.form</field>
|
||||
<field name="model">stock.demand.estimate.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
@@ -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"/>
|
||||
|
||||
<menuitem
|
||||
id="menu_stock_demand_estimate_wizard"
|
||||
parent="menu_stock_demand_planning"
|
||||
action="action_stock_demand_estimate_wizard"/>
|
||||
<menuitem id="stock_demand_estimate_wizard_menu"
|
||||
parent="stock_demand_planning_menu"
|
||||
action="stock_demand_estimate_wizard_action"/>
|
||||
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user