Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.0][mrp_multi_level] enable MRP view in product templates #297

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions mrp_multi_level/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
'name': 'MRP Multi Level',
'version': '11.0.1.0.1',
'version': '11.0.1.1.0',
'development_status': 'Beta',
'license': 'AGPL-3',
'author': 'Ucamco, '
Expand All @@ -24,7 +24,8 @@
'security/mrp_multi_level_security.xml',
'security/ir.model.access.csv',
'views/mrp_area_view.xml',
'views/product_view.xml',
'views/product_product_view.xml',
'views/product_template_view.xml',
'views/stock_location_view.xml',
'views/mrp_product_view.xml',
'wizards/mrp_inventory_procure_view.xml',
Expand Down
3 changes: 2 additions & 1 deletion mrp_multi_level/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from . import mrp_area
from . import stock_location
from . import product
from . import product_product
from . import product_template
from . import mrp_product
from . import mrp_move
from . import mrp_inventory
15 changes: 9 additions & 6 deletions mrp_multi_level/models/mrp_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# © 2016-18 Eficent Business and IT Consulting Services S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from math import ceil

from odoo import api, fields, models


Expand Down Expand Up @@ -118,15 +120,16 @@ def _compute_main_supplier(self):

@api.multi
def _adjust_qty_to_order(self, qty_to_order):
# TODO: consider mrp_qty_multiple?
self.ensure_one()
if not self.mrp_maximum_order_qty and not self.mrp_minimum_order_qty:
if (not self.mrp_maximum_order_qty and not
self.mrp_minimum_order_qty and self.mrp_qty_multiple == 1.0):
return qty_to_order
if qty_to_order < self.mrp_minimum_order_qty:
return self.mrp_minimum_order_qty
if self.mrp_qty_multiple:
multiplier = ceil(qty_to_order / self.mrp_qty_multiple)
qty_to_order = multiplier * self.mrp_qty_multiple
if self.mrp_maximum_order_qty and qty_to_order > \
self.mrp_maximum_order_qty:
qty = self.mrp_maximum_order_qty
else:
qty = qty_to_order
return qty
return self.mrp_maximum_order_qty
return qty_to_order
228 changes: 228 additions & 0 deletions mrp_multi_level/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
# Copyright 2018 Eficent Business and IT Consulting Services S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models


class ProductTemplate(models.Model):
_inherit = 'product.template'

mrp_applicable = fields.Boolean(string='MRP Applicable',
compute='_compute_mrp_applicable',
inverse='_set_mrp_applicable', store=True
)
mrp_exclude = fields.Boolean(string='Exclude from MRP',
compute='_compute_mrp_exclude',
inverse='_set_mrp_exclude', store=True
)
mrp_inspection_delay = fields.Integer(
string='Inspection Delay',
compute='_compute_mrp_inspection_delay',
inverse='_set_mrp_inspection_delay',
store=True
)
mrp_maximum_order_qty = fields.Float(
string='Maximum Order Qty',
compute='_compute_mrp_maximum_order_qty',
inverse='_set_mrp_maximum_order_qty', store=True
)
mrp_minimum_order_qty = fields.Float(
string='Minimum Order Qty',
compute='_compute_mrp_minimum_order_qty',
inverse='_set_mrp_minimum_order_qty', store=True
)
mrp_minimum_stock = fields.Float(
string='Minimum Stock',
compute='_compute_mrp_minimum_stock',
inverse='_set_mrp_minimum_stock', store=True
)
mrp_nbr_days = fields.Integer(
string='Nbr. Days',
compute='_compute_mrp_nbr_days',
inverse='_set_mrp_nbr_days', store=True,
help="Number of days to group demand for this product during the "
"MRP run, in order to determine the quantity to order.",
)
mrp_qty_multiple = fields.Float(
string='Qty Multiple', default=1.00,
compute='_compute_mrp_qty_multiple',
inverse='_set_mrp_qty_multiple', store=True
)
mrp_transit_delay = fields.Integer(
string='Transit Delay', default=0,
compute='_compute_mrp_transit_delay',
inverse='_set_mrp_transit_delay', store=True
)
mrp_verified = fields.Boolean(
string='Verified for MRP',
compute='_compute_mrp_verified',
inverse='_set_mrp_verified', store=True,
help="Identifies that this product has been verified "
"to be valid for the MRP.",
)

@api.depends('product_variant_ids', 'product_variant_ids.mrp_applicable')
def _compute_mrp_applicable(self):
unique_variants = self.filtered(
lambda template: len(template.product_variant_ids) == 1)
for template in unique_variants:
template.mrp_applicable = \
template.product_variant_ids.mrp_applicable
for template in (self - unique_variants):
template.mrp_applicable = False

@api.one
def _set_mrp_applicable(self):
if len(self.product_variant_ids) == 1:
self.product_variant_ids.mrp_applicable = self.mrp_applicable

@api.depends('product_variant_ids', 'product_variant_ids.mrp_exclude')
def _compute_mrp_exclude(self):
unique_variants = self.filtered(
lambda template: len(template.product_variant_ids) == 1)
for template in unique_variants:
template.mrp_exclude = \
template.product_variant_ids.mrp_exclude
for template in (self - unique_variants):
template.mrp_exclude = False

@api.one
def _set_mrp_exclude(self):
if len(self.product_variant_ids) == 1:
self.product_variant_ids.mrp_exclude = self.mrp_exclude

@api.depends('product_variant_ids',
'product_variant_ids.mrp_inspection_delay')
def _compute_mrp_inspection_delay(self):
unique_variants = self.filtered(
lambda template: len(template.product_variant_ids) == 1)
for template in unique_variants:
template.mrp_inspection_delay = \
template.product_variant_ids.mrp_inspection_delay
for template in (self - unique_variants):
template.mrp_inspection_delay = 0

@api.one
def _set_mrp_inspection_delay(self):
if len(self.product_variant_ids) == 1:
self.product_variant_ids.mrp_inspection_delay = \
self.mrp_inspection_delay

@api.depends('product_variant_ids',
'product_variant_ids.mrp_maximum_order_qty')
def _compute_mrp_maximum_order_qty(self):
unique_variants = self.filtered(
lambda template: len(template.product_variant_ids) == 1)
for template in unique_variants:
template.mrp_maximum_order_qty = \
template.product_variant_ids.mrp_maximum_order_qty
for template in (self - unique_variants):
template.mrp_maximum_order_qty = 0.0

@api.one
def _set_mrp_maximum_order_qty(self):
if len(self.product_variant_ids) == 1:
self.product_variant_ids.mrp_maximum_order_qty = \
self.mrp_maximum_order_qty

@api.depends('product_variant_ids',
'product_variant_ids.mrp_minimum_order_qty')
def _compute_mrp_minimum_order_qty(self):
unique_variants = self.filtered(
lambda template: len(template.product_variant_ids) == 1)
for template in unique_variants:
template.mrp_minimum_order_qty = \
template.product_variant_ids.mrp_minimum_order_qty
for template in (self - unique_variants):
template.mrp_minimum_order_qty = 0.0

@api.one
def _set_mrp_minimum_order_qty(self):
if len(self.product_variant_ids) == 1:
self.product_variant_ids.mrp_minimum_order_qty = \
self.mrp_minimum_order_qty

@api.depends('product_variant_ids',
'product_variant_ids.mrp_minimum_stock')
def _compute_mrp_minimum_stock(self):
unique_variants = self.filtered(
lambda template: len(template.product_variant_ids) == 1)
for template in unique_variants:
template.mrp_minimum_stock = \
template.product_variant_ids.mrp_minimum_stock
for template in (self - unique_variants):
template.mrp_minimum_stock = 0.0

@api.one
def _set_mrp_minimum_stock(self):
if len(self.product_variant_ids) == 1:
self.product_variant_ids.mrp_minimum_stock = \
self.mrp_minimum_stock

@api.depends('product_variant_ids',
'product_variant_ids.mrp_nbr_days')
def _compute_mrp_nbr_days(self):
unique_variants = self.filtered(
lambda template: len(template.product_variant_ids) == 1)
for template in unique_variants:
template.mrp_nbr_days = \
template.product_variant_ids.mrp_nbr_days
for template in (self - unique_variants):
template.mrp_nbr_days = 0.0

@api.one
def _set_mrp_nbr_days(self):
if len(self.product_variant_ids) == 1:
self.product_variant_ids.mrp_nbr_days = \
self.mrp_nbr_days

@api.depends('product_variant_ids',
'product_variant_ids.mrp_qty_multiple')
def _compute_mrp_qty_multiple(self):
unique_variants = self.filtered(
lambda template: len(template.product_variant_ids) == 1)
for template in unique_variants:
template.mrp_qty_multiple = \
template.product_variant_ids.mrp_qty_multiple
for template in (self - unique_variants):
template.mrp_qty_multiple = 1

@api.one
def _set_mrp_qty_multiple(self):
if len(self.product_variant_ids) == 1:
self.product_variant_ids.mrp_qty_multiple = \
self.mrp_qty_multiple

@api.depends('product_variant_ids',
'product_variant_ids.mrp_transit_delay')
def _compute_mrp_transit_delay(self):
unique_variants = self.filtered(
lambda template: len(template.product_variant_ids) == 1)
for template in unique_variants:
template.mrp_transit_delay = \
template.product_variant_ids.mrp_transit_delay
for template in (self - unique_variants):
template.mrp_transit_delay = 0.0

@api.one
def _set_mrp_transit_delay(self):
if len(self.product_variant_ids) == 1:
self.product_variant_ids.mrp_transit_delay = \
self.mrp_transit_delay

@api.depends('product_variant_ids',
'product_variant_ids.mrp_verified')
def _compute_mrp_verified(self):
unique_variants = self.filtered(
lambda template: len(template.product_variant_ids) == 1)
for template in unique_variants:
template.mrp_verified = \
template.product_variant_ids.mrp_verified
for template in (self - unique_variants):
template.mrp_verified = 0.0

@api.one
def _set_mrp_verified(self):
if len(self.product_variant_ids) == 1:
self.product_variant_ids.mrp_verified = \
self.mrp_verified
6 changes: 6 additions & 0 deletions mrp_multi_level/readme/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
11.0.1.1.0 (2018-08-30)
~~~~~~~~~~~~~~~~~~~~~~~

* [FIX] Consider *Qty Multiple* on product to propose the quantity to procure.
(`#297 <https://github.com/OCA/manufacture/pull/297>`_)

11.0.1.0.1 (2018-08-03)
~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 2 additions & 0 deletions mrp_multi_level/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* The functionality related to field *Nbr. Days* in products is not
functional for the time being. Please, stay tuned to future updates.
Binary file added mrp_multi_level/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading