Skip to content

Commit

Permalink
Track moves to release
Browse files Browse the repository at this point in the history
  • Loading branch information
guewen committed Sep 27, 2019
1 parent 54bda6c commit b817595
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 23 deletions.
7 changes: 3 additions & 4 deletions stock_virtual_reservation/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class StockMove(models.Model):
help="Available quantity minus virtually reserved by older"
" operations that do not have a real reservation yet",
)
need_rule_pull = fields.Boolean()

@api.depends()
def _compute_virtual_available_qty(self):
Expand Down Expand Up @@ -95,11 +96,9 @@ def _run_stock_rule(self):
"Product Unit of Measure"
)
for move in self:
# FIXME what to do if there is no pull rule?
# should we have a different state for moves that need a release?
if move.state not in ("confirmed", "waiting"):
if not move.need_rule_pull:
continue
if move.product_id.type not in ("consu", "product"):
if move.state not in ("confirmed", "waiting"):
continue
# do not use the computed field, because it will keep
# a value in cache that we cannot invalidate declaratively
Expand Down
14 changes: 10 additions & 4 deletions stock_virtual_reservation/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ class StockPicking(models.Model):

# Add store on the field, as it is quite used in the searches,
# and this is an easy-win to reduce the number of SQL queries.
picking_type_code = fields.Selection(
store=True,
)
picking_type_code = fields.Selection(store=True)
need_rule_pull = fields.Boolean(compute="_compute_need_rule_pull")

@api.depends("move_lines.need_rule_pull")
def _compute_need_rule_pull(self):
for picking in self:
picking.need_rule_pull = any(
move.need_rule_pull for move in picking
)

@api.multi
def release_virtual_reservation(self):
self.mapped('move_lines').release_virtual_reservation()
self.mapped("move_lines").release_virtual_reservation()
14 changes: 13 additions & 1 deletion stock_virtual_reservation/models/stock_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ def _run_pull(
# We still want to create the first part of the chain
and not self.picking_type_id.code == "outgoing"
):
moves = values.get("move_dest_ids")
# track the moves that needs to have their pull rule
# done
if moves:
moves.write({"need_rule_pull": True})
return True
return super()._run_pull(

super()._run_pull(
product_id,
product_qty,
product_uom,
Expand All @@ -36,6 +42,12 @@ def _run_pull(
origin,
values,
)
moves = values.get("move_dest_ids")
if moves:
moves.filtered(lambda r: r.need_rule_pull).write(
{"need_rule_pull": False}
)
return True


class ProcurementGroup(models.Model):
Expand Down
15 changes: 3 additions & 12 deletions stock_virtual_reservation/views/stock_move_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<field name="arch" type="xml">
<field name="product_uom_qty" position="after">
<field name="virtual_available_qty"/>
<field name="date_priority"/>
</field>
</field>
</record>
Expand All @@ -23,22 +24,11 @@
<field name="arch" type="xml">
<group name="main_grp_col2" position="inside">
<field name="virtual_available_qty"/>
<field name="date_priority"/>
</group>
</field>
</record>

<record id="view_move_release_search" model="ir.ui.view">
<field name="name">stock.move.release.search</field>
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock.view_move_search"/>
<field name="arch" type="xml">
<filter name="outgoing" position="after">
<separator/>
<filter string="To release" name="to_release" domain="[('state', 'in', ('confirmed', 'waiting')), ('picking_code', '=', 'outgoing')]" help="Stock Moves to release"/>
</filter>
</field>
</record>

<record id="stock_move_release_action" model="ir.actions.act_window">
<field name="name">Stock Moves To Release</field>
<field name="res_model">stock.move</field>
Expand All @@ -52,6 +42,7 @@
(0, 0, {'view_mode': 'form', 'view_id': ref('view_move_release_form')}),
]"/>
<field name="context">{'search_default_to_release': 1}</field>
<field name="domain">[('need_pull_rule', '=' , True)]</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Create a new stock movement
Expand Down
4 changes: 2 additions & 2 deletions stock_virtual_reservation/views/stock_picking_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="arch" type="xml">
<button name="action_confirm" position="after">
<field name="picking_type_code" invisible="1"/>
<field name="need_rule_pull" invisible="1"/>
<button name="release_virtual_reservation"
attrs="{'invisible': ['!', '&amp;', ('state', 'in', ('confirmed', 'waiting')), ('picking_type_code', '=', 'outgoing')]}"
attrs="{'invisible': [('need_rule_pull', '=', False)]}"
string="Release"
type="object"
class="oe_highlight"
Expand Down

0 comments on commit b817595

Please sign in to comment.