mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
Fixes, and add migration script
This commit is contained in:
committed by
davidborromeo
parent
cbc17ecc58
commit
edc87ee573
50
mrp_multi_level/migrations/11.0.2.0.0/post-migration.py
Normal file
50
mrp_multi_level/migrations/11.0.2.0.0/post-migration.py
Normal file
@@ -0,0 +1,50 @@
|
||||
# Copyright 2019 Eficent Business and IT Consulting Services, S.L.
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
import logging
|
||||
from odoo import api, SUPERUSER_ID
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
__name__ = "Upgrade to 11.0.2.0.0"
|
||||
|
||||
|
||||
def _migrate_product_to_product_mrp_area(env):
|
||||
_logger.info("Migrating product parameters to Product MRP Areas")
|
||||
env.cr.execute("""
|
||||
SELECT DISTINCT mrp_area.id, pr.id, pr.mrp_applicable, pr.mrp_exclude,
|
||||
pr.mrp_inspection_delay, pr.mrp_maximum_order_qty,
|
||||
pr.mrp_minimum_order_qty, pr.mrp_minimum_stock, pr.mrp_nbr_days,
|
||||
pr.mrp_qty_multiple, pr.mrp_transit_delay, pr.mrp_verified, pr.active
|
||||
FROM product_product AS pr
|
||||
CROSS JOIN mrp_area
|
||||
LEFT JOIN product_template AS pt
|
||||
ON pt.id = pr.product_tmpl_id
|
||||
WHERE pr.mrp_exclude = False
|
||||
AND pt.type = 'product'
|
||||
""")
|
||||
product_mrp_area_model = env['product.mrp.area']
|
||||
for mrp_area_id, product_id, mrp_applicable, mrp_exclude,\
|
||||
mrp_inspection_delay, mrp_maximum_order_qty, mrp_minimum_order_qty, \
|
||||
mrp_minimum_stock, mrp_nbr_days, mrp_qty_multiple, mrp_transit_delay,\
|
||||
mrp_verified, active in env.cr.fetchall():
|
||||
product_mrp_area_model.create({
|
||||
'mrp_area_id': mrp_area_id,
|
||||
'product_id': product_id,
|
||||
'mrp_applicable': mrp_applicable,
|
||||
'mrp_exclude': mrp_exclude,
|
||||
'mrp_inspection_delay': mrp_inspection_delay,
|
||||
'mrp_maximum_order_qty': mrp_maximum_order_qty,
|
||||
'mrp_minimum_order_qty': mrp_minimum_order_qty,
|
||||
'mrp_minimum_stock': mrp_minimum_stock,
|
||||
'mrp_nbr_days': mrp_nbr_days,
|
||||
'mrp_qty_multiple': mrp_qty_multiple,
|
||||
'mrp_transit_delay': mrp_transit_delay,
|
||||
'mrp_verified': mrp_verified,
|
||||
'active': active,
|
||||
})
|
||||
|
||||
|
||||
def migrate(cr, version):
|
||||
with api.Environment.manage():
|
||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||
_migrate_product_to_product_mrp_area(env)
|
||||
@@ -1,7 +1,7 @@
|
||||
# Copyright 2016 Ucamco - Wim Audenaert <wim.audenaert@ucamco.com>
|
||||
# Copyright 2016-18 Eficent Business and IT Consulting Services S.L.
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
import ast
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
@@ -41,11 +41,19 @@ class Product(models.Model):
|
||||
self.ensure_one()
|
||||
action = self.env.ref('mrp_multi_level.product_mrp_area_action')
|
||||
result = action.read()[0]
|
||||
ctx = ast.literal_eval(result.get('context'))
|
||||
if not ctx:
|
||||
ctx = {}
|
||||
mrp_areas = self.env['mrp.area'].search([])
|
||||
if len(mrp_areas) == 1:
|
||||
ctx.update({'default_mrp_area_id': mrp_areas[0].id})
|
||||
area_ids = self.mrp_area_ids.ids
|
||||
ctx.update({'default_product_id': self.id})
|
||||
if self.mrp_area_count != 1:
|
||||
result['domain'] = [('id', 'in', area_ids)]
|
||||
else:
|
||||
res = self.env.ref('mrp_multi_level.product_mrp_area_form', False)
|
||||
result['views'] = [(res and res.id or False, 'form')]
|
||||
result['res_id'] = area_ids[0]
|
||||
result['context'] = ctx
|
||||
return result
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Copyright 2018 Eficent Business and IT Consulting Services S.L.
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
import ast
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
@@ -28,12 +28,22 @@ class ProductTemplate(models.Model):
|
||||
self.ensure_one()
|
||||
action = self.env.ref('mrp_multi_level.product_mrp_area_action')
|
||||
result = action.read()[0]
|
||||
ctx = ast.literal_eval(result.get('context'))
|
||||
mrp_areas = self.env['mrp.area'].search([])
|
||||
if 'context' not in result:
|
||||
result['context'] = {}
|
||||
if len(mrp_areas) == 1:
|
||||
ctx.update({'default_mrp_area_id': mrp_areas[0].id})
|
||||
mrp_area_ids = self.with_context(
|
||||
active_test=False).mrp_area_ids.ids
|
||||
if len(self.product_variant_ids) == 1:
|
||||
variant = self.product_variant_ids[0]
|
||||
ctx.update({'default_product_id': variant.id})
|
||||
if len(mrp_area_ids) != 1:
|
||||
result['domain'] = [('id', 'in', mrp_area_ids)]
|
||||
else:
|
||||
res = self.env.ref('mrp_multi_level.product_mrp_area_form', False)
|
||||
result['views'] = [(res and res.id or False, 'form')]
|
||||
result['res_id'] = mrp_area_ids[0]
|
||||
result['context'] = ctx
|
||||
return result
|
||||
|
||||
@@ -59,28 +59,30 @@
|
||||
<field name="main_supplierinfo_id"/>
|
||||
</group>
|
||||
</group>
|
||||
<group string="MRP moves" name="mrp_moves" groups="base.group_no_one">
|
||||
<field name="mrp_move_ids" nolabel="1">
|
||||
<tree>
|
||||
<field name="mrp_action_date"/>
|
||||
<field name="mrp_date"/>
|
||||
<field name="current_date"/>
|
||||
<field name="mrp_origin"/>
|
||||
<field name="state"/>
|
||||
<field name="mrp_order_number"/>
|
||||
<field name="parent_product_id"/>
|
||||
<field name="name"/>
|
||||
<field name="mrp_qty"/>
|
||||
<field name="current_qty"/>
|
||||
<field name="running_availability"/>
|
||||
<field name="mrp_minimum_stock" />
|
||||
<field name="mrp_action"/>
|
||||
<field name="mrp_type"/>
|
||||
<field name="mrp_move_up_ids"/>
|
||||
<field name="mrp_processed"/>
|
||||
</tree>
|
||||
</field>
|
||||
</group>
|
||||
<notebook>
|
||||
<page name="mrp_moves" string="MRP Moves" groups="base.group_no_one">
|
||||
<field name="mrp_move_ids" nolabel="1">
|
||||
<tree>
|
||||
<field name="mrp_action_date"/>
|
||||
<field name="mrp_date"/>
|
||||
<field name="current_date"/>
|
||||
<field name="mrp_origin"/>
|
||||
<field name="state"/>
|
||||
<field name="mrp_order_number"/>
|
||||
<field name="parent_product_id"/>
|
||||
<field name="name"/>
|
||||
<field name="mrp_qty"/>
|
||||
<field name="current_qty"/>
|
||||
<field name="running_availability"/>
|
||||
<field name="mrp_minimum_stock" />
|
||||
<field name="mrp_action"/>
|
||||
<field name="mrp_type"/>
|
||||
<field name="mrp_move_up_ids"/>
|
||||
<field name="mrp_processed"/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
</notebook>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0"?>
|
||||
<odoo>
|
||||
|
||||
<record model="ir.ui.view" id="view_product_mrp_area_product_form">
|
||||
<record model="ir.ui.view" id="view_mrp_product_product_form">
|
||||
<field name="name">view.product.mrp.area.product.form</field>
|
||||
<field name="model">product.product</field>
|
||||
<field name="inherit_id" ref="product.product_normal_form_view"/>
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
<field name="arch" type="xml">
|
||||
<div name="button_box" position="inside">
|
||||
<button type="object"
|
||||
name="action_view_mrp_area_parameters"
|
||||
class="oe_stat_button"
|
||||
icon="fa-eject"
|
||||
groups="mrp.group_mrp_user,rma.group_mrp_manager">
|
||||
name="action_view_mrp_area_parameters"
|
||||
class="oe_stat_button"
|
||||
icon="fa-eject"
|
||||
groups="mrp.group_mrp_user,rma.group_mrp_manager">
|
||||
<field name="mrp_area_count" widget="statinfo"
|
||||
string="MRP Areas"/>
|
||||
</button>
|
||||
|
||||
@@ -531,7 +531,7 @@ class MultiLevelMrp(models.TransientModel):
|
||||
product_mrp_area.mrp_minimum_stock - \
|
||||
product_mrp_area - last_qty
|
||||
cm = self.create_move(
|
||||
product_mrp_area_id=product_mrp_area.id,
|
||||
product_mrp_area_id=product_mrp_area,
|
||||
mrp_date=last_date,
|
||||
mrp_qty=qtytoorder,
|
||||
name=name)
|
||||
@@ -562,7 +562,7 @@ class MultiLevelMrp(models.TransientModel):
|
||||
(product_mrp_area.mrp_nbr_days, )
|
||||
qtytoorder = product_mrp_area.mrp_minimum_stock - onhand - last_qty
|
||||
cm = self.create_move(
|
||||
product_mrp_area_id=product_mrp_area.id, mrp_date=last_date,
|
||||
product_mrp_area_id=product_mrp_area, mrp_date=last_date,
|
||||
mrp_qty=qtytoorder, name=name)
|
||||
qty_ordered = cm['qty_ordered']
|
||||
onhand += qty_ordered
|
||||
@@ -748,18 +748,18 @@ class MultiLevelMrp(models.TransientModel):
|
||||
for move in moves:
|
||||
qoh = qoh + move.mrp_qty
|
||||
move.running_availability = qoh
|
||||
|
||||
nbr_actions = product_mrp_area.mrp_move_ids.filtered(
|
||||
lambda m: m.mrp_action != 'none')
|
||||
horizon_4w = fields.Date.to_string(
|
||||
date.today() + timedelta(weeks=4))
|
||||
nbr_actions_4w = nbr_actions.filtered(
|
||||
lambda m: m.mrp_action_date < horizon_4w)
|
||||
if nbr_actions:
|
||||
product_mrp_area.write({
|
||||
'nbr_mrp_actions': len(nbr_actions),
|
||||
'nbr_mrp_actions_4w': len(nbr_actions_4w),
|
||||
})
|
||||
# TODO: Possible clean up needed here
|
||||
# nbr_actions = product_mrp_area.mrp_move_ids.filtered(
|
||||
# lambda m: m.mrp_action != 'none')
|
||||
# horizon_4w = fields.Date.to_string(
|
||||
# date.today() + timedelta(weeks=4))
|
||||
# nbr_actions_4w = nbr_actions.filtered(
|
||||
# lambda m: m.mrp_action_date < horizon_4w)
|
||||
# if nbr_actions:
|
||||
# product_mrp_area.write({
|
||||
# 'nbr_mrp_actions': len(nbr_actions),
|
||||
# 'nbr_mrp_actions_4w': len(nbr_actions_4w),
|
||||
# })
|
||||
logger.info('END MRP FINAL PROCESS')
|
||||
|
||||
@api.multi
|
||||
|
||||
Reference in New Issue
Block a user