mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[11.0][IMP] mrp_multi_level: able to group demand estimates or to ignore them.
This commit is contained in:
@@ -6,7 +6,8 @@
|
||||
|
||||
from math import ceil
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class ProductMRPArea(models.Model):
|
||||
@@ -98,11 +99,30 @@ class ProductMRPArea(models.Model):
|
||||
inverse_name="product_mrp_area_id",
|
||||
readonly=True,
|
||||
)
|
||||
group_estimate_days = fields.Integer(
|
||||
string="Group Days of Estimates",
|
||||
default=1,
|
||||
)
|
||||
_sql_constraints = [
|
||||
('product_mrp_area_uniq', 'unique(product_id, mrp_area_id)',
|
||||
'The product/MRP Area parameters combination must be unique.'),
|
||||
]
|
||||
|
||||
@api.multi
|
||||
@api.constrains(
|
||||
"mrp_minimum_order_qty", "mrp_maximum_order_qty", "mrp_qty_multiple",
|
||||
"mrp_minimum_stock", "mrp_nbr_days", "group_estimate_days",
|
||||
)
|
||||
def _check_negatives(self):
|
||||
values = self.read([
|
||||
"mrp_minimum_order_qty", "mrp_maximum_order_qty",
|
||||
"mrp_qty_multiple",
|
||||
"mrp_minimum_stock", "mrp_nbr_days", "group_estimate_days",
|
||||
])
|
||||
for rec in values:
|
||||
if any(v < 0 for v in rec.values()):
|
||||
raise ValidationError(_("You cannot use a negative number."))
|
||||
|
||||
@api.multi
|
||||
def name_get(self):
|
||||
return [(area.id, '[%s] %s' % (
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
<field name="mrp_exclude"/>
|
||||
<field name="mrp_verified"/>
|
||||
<field name="mrp_nbr_days"/>
|
||||
<field name="group_estimate_days"/>
|
||||
<!--hide delays for now-->
|
||||
<field name="mrp_transit_delay" invisible="1"/>
|
||||
<field name="mrp_inspection_delay" invisible="1"/>
|
||||
|
||||
@@ -58,7 +58,7 @@ class MultiLevelMrp(models.TransientModel):
|
||||
'purchase_order_id': None,
|
||||
'purchase_line_id': None,
|
||||
'stock_move_id': None,
|
||||
'mrp_qty': -daily_qty,
|
||||
'mrp_qty': -daily_qty * product_mrp_area.group_estimate_days,
|
||||
'current_qty': -daily_qty,
|
||||
'mrp_date': date,
|
||||
'current_date': date,
|
||||
@@ -360,21 +360,28 @@ class MultiLevelMrp(models.TransientModel):
|
||||
return True
|
||||
|
||||
@api.model
|
||||
def _init_mrp_move_from_forecast(self, product_mrp_area):
|
||||
def _estimates_domain(self, product_mrp_area):
|
||||
locations = product_mrp_area.mrp_area_id._get_locations()
|
||||
today = fields.Date.today()
|
||||
estimates = self.env['stock.demand.estimate'].search([
|
||||
return [
|
||||
('product_id', '=', product_mrp_area.product_id.id),
|
||||
('location_id', 'in', locations.ids),
|
||||
('date_range_id.date_end', '>=', today)
|
||||
])
|
||||
('date_range_id.date_end', '>=', fields.Date.today()),
|
||||
]
|
||||
|
||||
@api.model
|
||||
def _init_mrp_move_from_forecast(self, product_mrp_area):
|
||||
if not product_mrp_area.group_estimate_days:
|
||||
return False
|
||||
today = fields.Date.today()
|
||||
domain = self._estimates_domain(product_mrp_area)
|
||||
estimates = self.env['stock.demand.estimate'].search(domain)
|
||||
for rec in estimates:
|
||||
start = rec.date_range_id.date_start
|
||||
if start < today:
|
||||
start = today
|
||||
mrp_date = fields.Date.from_string(start)
|
||||
date_end = fields.Date.from_string(rec.date_range_id.date_end)
|
||||
delta = timedelta(days=1)
|
||||
delta = timedelta(days=product_mrp_area.group_estimate_days)
|
||||
while mrp_date <= date_end:
|
||||
mrp_move_data = \
|
||||
self._prepare_mrp_move_data_from_forecast(
|
||||
|
||||
Reference in New Issue
Block a user