[IMP] mrp_multi_level:

* Stock Moves Domain moved to product mrp area
This commit is contained in:
hveficent
2020-03-19 10:43:04 +01:00
committed by JasminSForgeFlow
parent b372d5da0d
commit 2a1c277c96
3 changed files with 53 additions and 27 deletions

View File

@@ -224,3 +224,38 @@ class ProductMRPArea(models.Model):
lambda r: r.main_supplierinfo_id and r.supply_method == "buy"
):
rec.mrp_minimum_order_qty = rec.main_supplierinfo_id.min_qty
def _in_stock_moves_domain(self):
self.ensure_one()
locations = self.mrp_area_id._get_locations()
return [
("product_id", "=", self.product_id.id),
("state", "not in", ["done", "cancel"]),
("product_qty", ">", 0.00),
("location_id", "not in", locations.ids),
("location_dest_id", "in", locations.ids),
]
def _out_stock_moves_domain(self):
self.ensure_one()
locations = self.mrp_area_id._get_locations()
return [
("product_id", "=", self.product_id.id),
("state", "not in", ["done", "cancel"]),
("product_qty", ">", 0.00),
("location_id", "in", locations.ids),
("location_dest_id", "not in", locations.ids),
]
def action_view_stock_moves(self, domain):
self.ensure_one()
action = self.env.ref("stock.stock_move_action").read()[0]
action["domain"] = domain
action["context"] = {}
return action
def action_view_incoming_stock_moves(self):
return self.action_view_stock_moves(self._in_stock_moves_domain())
def action_view_outgoing_stock_moves(self):
return self.action_view_stock_moves(self._out_stock_moves_domain())

View File

@@ -31,7 +31,22 @@
<field name="arch" type="xml">
<form string="Product MRP Area parameters">
<sheet>
<div class="oe_button_box" name="button_box" />
<div class="oe_button_box" name="button_box">
<button
name="action_view_incoming_stock_moves"
string="Incoming Moves"
type="object"
class="oe_stat_button"
icon="fa-list"
/>
<button
name="action_view_outgoing_stock_moves"
string="Outgoing Moves"
type="object"
class="oe_stat_button"
icon="fa-list"
/>
</div>
<widget
name="web_ribbon"
title="Archived"

View File

@@ -338,37 +338,13 @@ class MultiLevelMrp(models.TransientModel):
"""This method is meant to be inherited to add a forecast mechanism."""
return True
# TODO: move this methods to product_mrp_area?? to be able to
# show moves with an action
@api.model
def _in_stock_moves_domain(self, product_mrp_area):
locations = product_mrp_area.mrp_area_id._get_locations()
return [
("product_id", "=", product_mrp_area.product_id.id),
("state", "not in", ["done", "cancel"]),
("product_qty", ">", 0.00),
("location_id", "not in", locations.ids),
("location_dest_id", "in", locations.ids),
]
@api.model
def _out_stock_moves_domain(self, product_mrp_area):
locations = product_mrp_area.mrp_area_id._get_locations()
return [
("product_id", "=", product_mrp_area.product_id.id),
("state", "not in", ["done", "cancel"]),
("product_qty", ">", 0.00),
("location_id", "in", locations.ids),
("location_dest_id", "not in", locations.ids),
]
@api.model
def _init_mrp_move_from_stock_move(self, product_mrp_area):
move_obj = self.env["stock.move"]
mrp_move_obj = self.env["mrp.move"]
in_domain = self._in_stock_moves_domain(product_mrp_area)
in_domain = product_mrp_area._in_stock_moves_domain()
in_moves = move_obj.search(in_domain)
out_domain = self._out_stock_moves_domain(product_mrp_area)
out_domain = product_mrp_area._out_stock_moves_domain()
out_moves = move_obj.search(out_domain)
if in_moves:
for move in in_moves: