stock mass action por dependencia de sotck picking batch extended

This commit is contained in:
santiky 2022-04-22 18:45:57 +02:00
parent 448f889f12
commit 3a0a965589
Signed by: snt
GPG key ID: A9FD34930EADBE71
89 changed files with 11072 additions and 0 deletions

View file

@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import mass_action

View file

@ -0,0 +1,88 @@
# Copyright 2014 Camptocamp SA - Guewen Baconnier
# Copyright 2018 Tecnativa - Vicent Cubells
# Copyright 2019 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, api
from odoo.models import TransientModel
class StockPickingMassAction(TransientModel):
_name = 'stock.picking.mass.action'
_description = 'Stock Picking Mass Action'
@api.model
def _default_check_availability(self):
return self.env.context.get('check_availability', False)
@api.model
def _default_transfer(self):
return self.env.context.get('transfer', False)
def _default_picking_ids(self):
return self.env['stock.picking'].browse(
self.env.context.get('active_ids'))
confirm = fields.Boolean(
string='Mark as Todo',
default=True,
help="check this box if you want to mark as Todo the"
" selected Pickings.",
)
check_availability = fields.Boolean(
string='Check Availability',
default=lambda self: self._default_check_availability(),
help="check this box if you want to check the availability of"
" the selected Pickings.",
)
transfer = fields.Boolean(
string='Transfer',
default=lambda self: self._default_transfer(),
help="check this box if you want to transfer all the selected"
" pickings.\n You'll not have the possibility to realize a"
" partial transfer.\n If you want to do that, please do it"
" manually on the picking form.",
)
picking_ids = fields.Many2many(
string='Pickings',
comodel_name="stock.picking",
default=lambda self: self._default_picking_ids(),
help="",
)
@api.multi
def mass_action(self):
self.ensure_one()
# Get draft pickings and confirm them if asked
if self.confirm:
draft_picking_lst = self.picking_ids.\
filtered(lambda x: x.state == 'draft').\
sorted(key=lambda r: r.scheduled_date)
draft_picking_lst.action_confirm()
# check availability if asked
if self.check_availability:
pickings_to_check = self.picking_ids.\
filtered(lambda x: x.state not in [
'draft',
'cancel',
'done',
]).\
sorted(key=lambda r: r.scheduled_date)
pickings_to_check.action_assign()
# Get all pickings ready to transfer and transfer them if asked
if self.transfer:
assigned_picking_lst = self.picking_ids.\
filtered(lambda x: x.state == 'assigned').\
sorted(key=lambda r: r.scheduled_date)
quantities_done = sum(
move_line.qty_done for move_line in
assigned_picking_lst.mapped('move_line_ids').filtered(
lambda m: m.state not in ('done', 'cancel')))
if not quantities_done:
return assigned_picking_lst.action_immediate_transfer_wizard()
if any([pick._check_backorder() for pick in assigned_picking_lst]):
return assigned_picking_lst.action_generate_backorder_wizard()
assigned_picking_lst.action_done()

View file

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_stock_picking_mass_action_form" model="ir.ui.view">
<field name="model">stock.picking.mass.action</field>
<field name="arch" type="xml">
<form string="Mass Action for the selected stock picking">
<group>
<field name="confirm"/>
<field name="check_availability"/>
<field name="transfer"/>
</group>
<footer>
<button name="mass_action" string="Apply" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel"/>
</footer>
</form>
</field>
</record>
<!-- Confirm Action -->
<record id="action_confirm" model="ir.actions.act_window">
<field name="name">Mark as Todo</field>
<field name="res_model">stock.picking.mass.action</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="binding_model_id" ref="stock.model_stock_picking" />
</record>
<!-- Check Availability Action -->
<record id="action_check_availability" model="ir.actions.act_window">
<field name="name">Check Availability</field>
<field name="res_model">stock.picking.mass.action</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="context">{'check_availability': 1}</field>
<field name="binding_model_id" ref="stock.model_stock_picking" />
</record>
<!-- Transfer Action -->
<record id="action_transfer" model="ir.actions.act_window">
<field name="name">Transfer</field>
<field name="res_model">stock.picking.mass.action</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="context">{'check_availability': 1, 'transfer': 1,}</field>
<field name="binding_model_id" ref="stock.model_stock_picking" />
</record>
</odoo>