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 committed Jan 25, 2023
1 parent 437046c commit ab5c6e5
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 47 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,
}
48 changes: 27 additions & 21 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 = 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,24 @@ 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):
""" 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)


# @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
# """
# import pdb; pdb.set_trace()
# recs = []
# for vals in vals_list:
# if vals.get('allocation'):
# allocation, qty = vals.pop('allocation')
# rec = super().create(vals)
# allocation.copy({
# 'stock_move_id': rec.id,
# 'requested_product_uom_qty': qty,
# })
# recs.append(rec)
# else:
# recs.append(super().create(vals))
# return recs
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
33 changes: 17 additions & 16 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,24 +56,25 @@ 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)])
Expand Down
10 changes: 6 additions & 4 deletions stock_request_ux/views/stock_picking_views.xml
@@ -1,14 +1,16 @@
<?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', '=', [])]}">
<!-- Probar -->
<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
3 changes: 2 additions & 1 deletion stock_request_ux/views/stock_request_order_views.xml
Expand Up @@ -7,7 +7,8 @@
<field name="arch" type="xml">
<field name="picking_policy" position="after">
<field name="route_ids" invisible="1"/>
<field name="route_id" domain="[('id', 'in', route_ids)]"/>
<field name="route_id"/>
<!-- domain="[('id', 'in', route_ids)]" -->
</field>
<field name="product_uom_qty" position="after">
<button name="button_cancel_remaining" icon="fa-ban" type="object" title="Cancelar Pendiente. Se van a cancelar todos los movimientos asociados que no esten realizados." confirm="Se van a cancelar todos los movimientos asociados que no esten realizados. Esto no puede ser revertido, seguro que desea continuar?" states="open"/>
Expand Down
3 changes: 2 additions & 1 deletion stock_ux/models/stock_move.py
Expand Up @@ -174,4 +174,5 @@ 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 ab5c6e5

Please sign in to comment.