Skip to content

Commit

Permalink
Merge e182513 into 3712b8c
Browse files Browse the repository at this point in the history
  • Loading branch information
LoisRForgeFlow committed Jan 5, 2020
2 parents 3712b8c + e182513 commit 6bfbb2f
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 22 deletions.
1 change: 1 addition & 0 deletions mrp_multi_level/__manifest__.py
Expand Up @@ -27,6 +27,7 @@
'views/product_product_views.xml',
'views/product_template_views.xml',
'views/product_mrp_area_views.xml',
'views/mrp_move_views.xml',
'views/stock_location_views.xml',
'wizards/mrp_inventory_procure_views.xml',
'views/mrp_inventory_views.xml',
Expand Down
18 changes: 18 additions & 0 deletions mrp_multi_level/models/mrp_inventory.py
Expand Up @@ -98,3 +98,21 @@ def _compute_order_release_date(self):
if order_release_date < today:
order_release_date = today
rec.order_release_date = order_release_date

@api.multi
def _get_demand_mrp_moves_domain(self):
self.ensure_one()
return [
('product_mrp_area_id', '=', self.product_mrp_area_id.id),
('mrp_type', '=', 'd'),
('mrp_date', '=', self.date),
]

@api.multi
def action_view_demand_mrp_moves(self):
action = self.env.ref("mrp_multi_level.mrp_move_action")
moves_domain = self._get_demand_mrp_moves_domain()
moves = self.env['mrp.move'].search(moves_domain)
result = action.read()[0]
result["domain"] = [("id", "in", moves.ids)]
return result
16 changes: 15 additions & 1 deletion mrp_multi_level/models/mrp_move.py
Expand Up @@ -13,7 +13,7 @@ class MrpMove(models.Model):

product_mrp_area_id = fields.Many2one(
comodel_name="product.mrp.area",
string="Product", index=True,
string="Product MRP Area", index=True,
required=True,
)
mrp_area_id = fields.Many2one(
Expand Down Expand Up @@ -44,6 +44,20 @@ class MrpMove(models.Model):
column2="order_id",
string="Planned Orders UP",
)
mrp_move_up_ids = fields.Many2many(
comodel_name="mrp.move",
relation="mrp_move_rel",
column1="move_id",
column2="move_up_id",
string="MRP Move UP",
)
mrp_move_down_ids = fields.Many2many(
comodel_name="mrp.move",
relation="mrp_move_rel",
column1="move_up_id",
column2="move_id",
string="MRP Move DOWN",
)
mrp_order_number = fields.Char(string='Order Number')
mrp_origin = fields.Selection(
selection=[('mo', 'Manufacturing Order'),
Expand Down
4 changes: 4 additions & 0 deletions mrp_multi_level/views/mrp_inventory_views.xml
Expand Up @@ -43,6 +43,10 @@
<field name="uom_id" groups="product.group_uom"/>
<field name="initial_on_hand_qty"/>
<field name="demand_qty"/>
<button string="See demand moves"
name="action_view_demand_mrp_moves"
icon="fa fa-list" type="object"
attrs="{'invisible':[('demand_qty','=',0)]}"/>
<field name="supply_qty"/>
<field name="final_on_hand_qty"/>
<field name="to_procure"/>
Expand Down
91 changes: 91 additions & 0 deletions mrp_multi_level/views/mrp_move_views.xml
@@ -0,0 +1,91 @@
<?xml version="1.0"?>
<odoo>

<record id="mrp_move_form" model="ir.ui.view">
<field name="name">mrp.move.form</field>
<field name="model">mrp.move</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="MRP Move" create="false" edit="false">
<sheet>
<group>
<field name="product_mrp_area_id"/>
<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="mrp_type"/>
</group>
<notebook>
<page name="requirements_pegging" string="Requirements pegging">
<group name="move_up" string="Upstream demand">
<field name="mrp_move_up_ids" nolabel="1"/>
</group>
<group name="move_down" string="Downstream demand">
<field name="mrp_move_down_ids" nolabel="1"/>
</group>
</page>
<page name="planned_orders" string="Planned Orders">
<field name="planned_order_up_ids" nolabel="1"/>
</page>
</notebook>
</sheet>
</form>
</field>
</record>

<record id="mrp_move_tree" model="ir.ui.view">
<field name="name">mrp.move.tree</field>
<field name="model">mrp.move</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="MRP move" create="false" edit="false">
<field name="product_mrp_area_id"/>
<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="mrp_type"/>
<field name="planned_order_up_ids"/>
<field name="mrp_move_up_ids"/>
<field name="mrp_move_down_ids"/>
</tree>
</field>
</record>

<record id="mrp_move_search" model="ir.ui.view">
<field name="name">mrp.move.search</field>
<field name="model">mrp.move</field>
<field name="type">search</field>
<field name="arch" type="xml">
<search string="MRP move">
<field name="company_id" groups="base.group_multi_company"/>
<group name="select" expand="0" string="Selection...">
<field name="product_id"/>
<field name="mrp_area_id"/>
</group>
</search>
</field>
</record>

<record id="mrp_move_action" model="ir.actions.act_window">
<field name="name">MRP move</field>
<field name="res_model">mrp.move</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="mrp_move_tree"/>
<field name="search_view_id" ref="mrp_move_search"/>
</record>

</odoo>
63 changes: 42 additions & 21 deletions mrp_multi_level/wizards/mrp_multi_level.py
Expand Up @@ -86,26 +86,27 @@ def _prepare_mrp_move_data_from_stock_move(
origin = 'po'
po = move.purchase_line_id.order_id.id
po_line = move.purchase_line_id.id
if move.production_id:
elif move.production_id:
order_number = move.production_id.name
origin = 'mo'
mo = move.production_id.id
elif move.move_dest_ids:
for move_dest_id in move.move_dest_ids:
if move_dest_id.production_id:
order_number = move_dest_id.production_id.name
origin = 'mo'
mo = move_dest_id.production_id.id
if move_dest_id.production_id.product_id:
parent_product_id = \
move_dest_id.production_id.product_id.id
else:
parent_product_id = move_dest_id.product_id.id
else:
# TODO: move.move_dest_id -> move.move_dest_ids. DONE, review
if move.move_dest_ids:
# move_dest_id = move.move_dest_ids[:1]
for move_dest_id in move.move_dest_ids:
if move_dest_id.production_id:
order_number = move_dest_id.production_id.name
origin = 'mo'
mo = move_dest_id.production_id.id
if move_dest_id.production_id.product_id:
parent_product_id = \
move_dest_id.production_id.product_id.id
else:
parent_product_id = move_dest_id.product_id.id
if order_number is None:
order_number = move.name
if move.picking_id:
order_number = move.picking_id.name
else:
order_number = move.name
origin = "mv"
mrp_date = date.today()
if datetime.date(datetime.strptime(
move.date_expected,
Expand Down Expand Up @@ -202,7 +203,8 @@ def _get_action_and_supply_dates(self, product_mrp_area, mrp_date):

@api.model
def explode_action(
self, product_mrp_area_id, mrp_action_date, name, qty, action
self, product_mrp_area_id, mrp_action_date, name, qty, action,
values=None
):
"""Explode requirements."""
mrp_date_demand = mrp_action_date
Expand Down Expand Up @@ -236,6 +238,9 @@ def explode_action(
mrp_date_demand_2,
bom, name)
mrpmove_id2 = self.env['mrp.move'].create(move_data)
if 'move_up_ids' in values:
mrpmove_id2.mrp_move_up_ids = [
(6, 0, values['move_up_ids'])]
if hasattr(action, "mrp_move_down_ids"):
action.mrp_move_down_ids = [(4, mrpmove_id2.id)]
return True
Expand Down Expand Up @@ -275,7 +280,7 @@ def create_planned_order(
if product_mrp_area_id.supply_method == 'manufacture':
self.explode_action(
product_mrp_area_id, mrp_action_date,
name, qty, planned_order)
name, qty, planned_order, values)

values['qty_ordered'] = qty_ordered
log_msg = '[%s] %s: qty_ordered = %s' % (
Expand Down Expand Up @@ -533,6 +538,7 @@ def _init_mrp_move_grouped_demand(self, nbr_create, product_mrp_area):
last_qty = 0.00
onhand = product_mrp_area.qty_available
grouping_delta = product_mrp_area.mrp_nbr_days
grouped_demand_moves = self.env['mrp.move']
for move in product_mrp_area.mrp_move_ids:
if self._exclude_move(move):
continue
Expand All @@ -546,11 +552,15 @@ def _init_mrp_move_grouped_demand(self, nbr_create, product_mrp_area):
name = 'Grouped Demand for %d Days' % grouping_delta
qtytoorder = product_mrp_area.mrp_minimum_stock - \
onhand - last_qty
values = {
'move_up_ids': grouped_demand_moves.ids,
}
cm = self.create_action(
product_mrp_area_id=product_mrp_area,
mrp_date=last_date,
mrp_qty=qtytoorder,
name=name)
name=name,
values=values)
qty_ordered = cm.get('qty_ordered', 0.0)
onhand = onhand + last_qty + qty_ordered
last_date = None
Expand All @@ -563,18 +573,25 @@ def _init_mrp_move_grouped_demand(self, nbr_create, product_mrp_area):
if not last_date or last_qty == 0.0:
last_date = fields.Date.from_string(move.mrp_date)
last_qty = move.mrp_qty
grouped_demand_moves |= move
else:
last_qty += move.mrp_qty
grouped_demand_moves |= move
else:
last_date = fields.Date.from_string(move.mrp_date)
onhand += move.mrp_qty
grouped_demand_moves |= move

if last_date and last_qty != 0.00:
name = 'Grouped Demand for %d Days' % grouping_delta
qtytoorder = product_mrp_area.mrp_minimum_stock - onhand - last_qty
values = {
'move_up_ids': grouped_demand_moves.ids,
}
cm = self.create_action(
product_mrp_area_id=product_mrp_area, mrp_date=last_date,
mrp_qty=qtytoorder, name=name)
mrp_qty=qtytoorder, name=name,
values=values)
qty_ordered = cm.get('qty_ordered', 0.0)
onhand += qty_ordered
nbr_create += 1
Expand Down Expand Up @@ -610,10 +627,14 @@ def _mrp_calculation(self, mrp_lowest_llc, mrp_areas):
qtytoorder = product_mrp_area.mrp_minimum_stock - \
onhand - move.mrp_qty
if qtytoorder > 0.0:
values = {
'move_up_ids': move.ids,
}
cm = self.create_action(
product_mrp_area_id=product_mrp_area,
mrp_date=move.mrp_date,
mrp_qty=qtytoorder, name=move.name)
mrp_qty=qtytoorder, name=move.name,
values=values)
qty_ordered = cm['qty_ordered']
onhand += move.mrp_qty + qty_ordered
nbr_create += 1
Expand Down

0 comments on commit 6bfbb2f

Please sign in to comment.