Skip to content

Commit

Permalink
[MIG] stock_request_ux: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
vib-adhoc authored and Bruno-Zanotti committed Apr 12, 2023
1 parent 85fc40d commit 2a7322c
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 45 deletions.
4 changes: 2 additions & 2 deletions stock_request_ux/__manifest__.py
Expand Up @@ -19,7 +19,7 @@
##############################################################################
{
'name': 'Stock Request UX',
'version': "15.0.1.0.0",
'version': "16.0.1.0.0",
'category': 'Warehouse Management',
'sequence': 14,
'summary': '',
Expand All @@ -42,7 +42,7 @@
],
'demo': [
],
'installable': False,
'installable': True,
'auto_install': False,
'application': False,
}
39 changes: 22 additions & 17 deletions stock_request_ux/models/stock_move.py
Expand Up @@ -9,9 +9,12 @@
class StockMove(models.Model):
_inherit = 'stock.move'

request_order_id = fields.Many2one(
related='stock_request_ids.order_id',
)
request_order_id = fields.Many2one("stock.request.order", compute="_compute_request_order_id")

@api.depends('stock_request_ids')
def _compute_request_order_id(self):
for rec in self:
rec.request_order_id = rec.stock_request_ids.mapped('order_id')

def _split(self, qty, restrict_partner_id=False):
""" When we are on a move created by a stock_request and we create a
Expand All @@ -30,21 +33,23 @@ def _split(self, qty, restrict_partner_id=False):
allocation.requested_product_uom_qty -= to_allocate

return move_val_list
@api.model
def create(self, vals):

@api.model_create_multi
def create(self, vals_list):
""" When we are on a move created by a stock_request and we create a
backorder, we create a new allocation linked to this new move and
update quantities
"""
if vals.get('allocation'):
allocation, qty = vals.pop('allocation')
res = super().create(vals)
allocation.copy({
'stock_move_id': res.id,
'requested_product_uom_qty': qty,
})
return res
else:
return super().create(vals)

ids = []
for vals in vals_list:
if vals.get('allocation'):
allocation, qty = vals.pop('allocation')
id = super().create(vals).id
ids += [id]
allocation.copy({
'stock_move_id': id,
'requested_product_uom_qty': qty,
})
else:
ids += [super().create(vals).id]
return self.browse(ids)
4 changes: 2 additions & 2 deletions stock_request_ux/models/stock_picking.py
Expand Up @@ -18,10 +18,10 @@ class StockPicking(models.Model):
compute='_compute_stock_request_order_ids',
)

@api.depends('move_lines')
@api.depends('move_ids')
def _compute_stock_request_order_ids(self):
for rec in self:
rec.stock_request_order_ids = rec.move_lines.mapped(
rec.stock_request_order_ids = rec.move_ids.mapped(
'stock_request_ids.order_id')
rec.stock_request_order_count = len(
rec.stock_request_order_ids)
Expand Down
4 changes: 2 additions & 2 deletions stock_request_ux/models/stock_request.py
Expand Up @@ -14,7 +14,7 @@ class StockRequest(models.Model):
picking_count = fields.Integer(
compute='_compute_picking_ids',
)
# clean this field because of because of _check_product_stock_request
# clean this field because of _check_product_stock_request
# and the fact that we add copy=True to stock_request_ids
procurement_group_id = fields.Many2one(
copy=False,
Expand Down Expand Up @@ -46,7 +46,7 @@ def _compute_picking_ids(self):
def action_cancel(self):
""" Con esto queremos cancelar todos lo moves/pickings vinculados (que
se hayan generado por la rule). No es muy elegante buscar por producto
pero al no estar almacenandno el link al request fue la mas facil.
pero al no estar almacenado el link al request fue la mas facil.
TODO: supongo que lo ideal seria:
1) poder identificar bien las lineas, ya sea llevando el stock request
a cada move y no solo el inicial, o obteniendo el move original y luego
Expand Down
35 changes: 18 additions & 17 deletions stock_request_ux/models/stock_request_order.py
Expand Up @@ -14,10 +14,10 @@ class StockRequestOrder(models.Model):
copy=True,
)
route_id = fields.Many2one(
'stock.location.route',
'stock.route',
)
route_ids = fields.Many2many(
'stock.location.route',
'stock.route',
compute='_compute_route_ids',
readonly=True,
string="Routes"
Expand Down Expand Up @@ -56,30 +56,31 @@ def _compute_picking_ids(self):
rec.picking_ids = all_moves.mapped('picking_id')
rec.picking_count = len(rec.picking_ids)

@api.model
def create(self, vals):
rec = super().create(vals)
if not rec.procurement_group_id:
# setamos al group el partner del warehouse para que se propague
# a los pickings
group = self.env['procurement.group'].create(
{'partner_id': rec.warehouse_id.partner_id.id})
rec.procurement_group_id = group.id
for stock_rq in rec.stock_request_ids:
stock_rq.write(
{'procurement_group_id': rec.procurement_group_id.id})
return rec
@api.model_create_multi
def create(self, vals_list):
recs = super().create(vals_list)
for rec in recs:
if not rec.procurement_group_id:
# setamos al group el partner del warehouse para que se propague
# a los pickings
group = self.env['procurement.group'].create(
{'partner_id': rec.warehouse_id.partner_id.id})
rec.procurement_group_id = group.id
for stock_rq in rec.stock_request_ids:
stock_rq.write(
{'procurement_group_id': rec.procurement_group_id.id})
return recs

@api.depends('warehouse_id', 'location_id')
def _compute_route_ids(self):
for rec in self:
routes = self.env['stock.location.route'].search(
routes = self.env['stock.route'].search(
['|',
('company_id', '=', rec.company_id.id),
('company_id', '=', False)])
parents = rec.get_parents().ids
rec.route_ids = routes.filtered(lambda r: any(
p.action == 'pull' and p.location_id.id in parents for p in r.rule_ids))
p.action == 'pull' and p.location_dest_id.id in parents for p in r.rule_ids))

def get_parents(self):
location = self.location_id
Expand Down
12 changes: 12 additions & 0 deletions stock_request_ux/views/product_product_views.xml
Expand Up @@ -12,4 +12,16 @@
</button>
</field>
</record>
<record id="product_product_view_form_easy_inherit_stock" model="ir.ui.view">
<field name="name">product.product.view.form.easy.inherit.stock</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="stock.product_product_view_form_easy_inherit_stock"/>
<field name="arch" type="xml">
<button name="%(stock.action_product_replenish)d" position="attributes">
<attribute name="invisible">True</attribute>
<attribute name="groups"></attribute>
<attribute name="attrs">{}</attribute>
</button>
</field>
</record>
</odoo>
9 changes: 5 additions & 4 deletions stock_request_ux/views/stock_picking_views.xml
@@ -1,14 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="view_picking_form" model="ir.ui.view">
<field name="name">stock.picking.form</field>
<field name="model">stock.picking</field>
<field name="groups_id" eval="[(4, ref('stock_request.group_stock_request_order'))]"/>
<field name="inherit_id" ref="stock_request.view_picking_form"/>
<field name="arch" type="xml">
<button name="action_view_stock_request" position="replace">
<button type="object" name="action_view_stock_order_request" class="oe_stat_button" icon="fa-chain" attrs="{'invisible':[('stock_request_order_ids', '=', [])]}">
<button name="action_view_stock_request" position="attributes">
<attribute name="groups">!stock_request.group_stock_request_order</attribute>
</button>
<button name="action_view_stock_request" position="after">
<button type="object" name="action_view_stock_order_request" class="oe_stat_button" icon="fa-chain" attrs="{'invisible':[('stock_request_order_ids', '=', [])]}" groups="stock_request.group_stock_request_order">
<field name="stock_request_order_count" widget="statinfo" string="Stock Request Orders"/>
<field name="stock_request_order_ids" invisible="1"/>
</button>
Expand Down
2 changes: 1 addition & 1 deletion stock_ux/models/stock_move.py
Expand Up @@ -174,4 +174,4 @@ def check_cancel(self):
return
if self.filtered(
lambda x: x.picking_id and x.state == 'cancel' and not self.user_has_groups('stock_ux.allow_picking_cancellation')):
raise ValidationError("Only User with 'Picking cancelation allow' rights can cancel pickings")
raise ValidationError("Only User with 'Picking cancelation allow' rights can cancel pickings")

0 comments on commit 2a7322c

Please sign in to comment.