-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] stock_picking_out_change_picking_type
For outgoing picking documents, enables changing picking operation. This could be achieved only for pickings in an early state (not done or cancel).
- Loading branch information
Showing
11 changed files
with
219 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import models | ||
from . import wizards |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# © 2024 Solvos Consultoría Informática (<http://www.solvos.es>) | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
|
||
{ | ||
"name": "Pickings - Change Picking Operation", | ||
"summary": """ | ||
For outgoing picking documents, enables changing picking operation | ||
""", | ||
"author": "Solvos", | ||
"license": "AGPL-3", | ||
"version": "13.0.1.0.0", | ||
"category": "stock", | ||
"website": "https://github.com/solvosci/slv-stock", | ||
"depends": ["stock_move_change_source_location"], | ||
"data": [ | ||
"wizards/stock_picking_out_change_picking_type_views.xml", | ||
"views/stock_picking_views.xml", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import stock_picking |
27 changes: 27 additions & 0 deletions
27
stock_picking_out_change_picking_type/models/stock_picking.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# © 2024 Solvos Consultoría Informática (<http://www.solvos.es>) | ||
# License AGPL-3.0 (https://www.gnu.org/licenses/agpl-3.0.html) | ||
|
||
from odoo import models, fields | ||
|
||
|
||
class StockPicking(models.Model): | ||
_inherit = "stock.picking" | ||
|
||
change_picking_type_enabled = fields.Boolean( | ||
compute="_change_picking_type_enabled", | ||
string="Is Picking Operation Change Enabled", | ||
help= | ||
""" | ||
Technical field indicating whether | ||
""", | ||
) | ||
|
||
def _change_picking_type_enabled(self): | ||
available_states = self.env[ | ||
"stock.move.change.source.location.wizard" | ||
]._get_allowed_states() | ||
allowed_picks = self.filtered( | ||
lambda x: x.state in available_states and x.picking_type_code == "outgoing" | ||
) | ||
allowed_picks.write({"change_picking_type_enabled": True}) | ||
(self - allowed_picks).write({"change_picking_type_enabled": False}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* David Alonso <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
For outgoing picking documents, enables changing picking operation. | ||
|
||
This could be achieved only for pickings in an early state (not done or cancel). |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions
21
stock_picking_out_change_picking_type/views/stock_picking_views.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<record id="view_picking_form" model="ir.ui.view"> | ||
<field name="name">stock.picking.form (in stock_picking_out_change_picking_type)</field> | ||
<field name="model">stock.picking</field> | ||
<field name="inherit_id" ref="stock.view_picking_form"/> | ||
<field name="arch" type="xml"> | ||
<header position="inside"> | ||
<field name="change_picking_type_enabled" invisible="1" /> | ||
<button | ||
name="%(action_stock_picking_change_picking_type)d" | ||
type="action" | ||
string="Change Picking Operation" | ||
groups="stock.group_stock_manager" | ||
attrs="{'invisible': [('change_picking_type_enabled', '=', False)]}" | ||
> | ||
</button> | ||
</header> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import stock_picking_out_change_picking_type |
82 changes: 82 additions & 0 deletions
82
stock_picking_out_change_picking_type/wizards/stock_picking_out_change_picking_type.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# © 2024 Solvos Consultoría Informática (<http://www.solvos.es>) | ||
# License AGPL-3.0 (https://www.gnu.org/licenses/agpl-3.0.html) | ||
|
||
from odoo import _, api, fields, models | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class ReturnPicking(models.TransientModel): | ||
_inherit = "stock.picking.out.change.picking.type.wizard" | ||
_description = "Stock Picking Out Change Picking Type Wizard" | ||
_check_company_auto = True | ||
|
||
@api.model | ||
def default_get(self, fields): | ||
res = super().default_get(fields) | ||
active_model = self.env.context["active_model"] | ||
active_ids = self.env.context["active_ids"] or [] | ||
picking = self.env[active_model].browse(active_ids) | ||
res.update({"picking_id": picking.id}) | ||
return res | ||
|
||
picking_id = fields.Many2one( | ||
comodel_name="stock.picking", | ||
required=True, | ||
readonly=True, | ||
) | ||
company_id = fields.Many2one( | ||
related="picking_id.company_id", | ||
required=True, | ||
store=True, | ||
) | ||
old_picking_type_id = fields.Many2one( | ||
string="Current Operation Type", | ||
related="picking_id.picking_type_id", | ||
) | ||
picking_type_id = fields.Many2one( | ||
comodel_name="stock.picking.type", | ||
check_company=True, | ||
domain=[("code", "=", "outgoing")], | ||
string="New Operation Type", | ||
) | ||
location_id = fields.Many2one( | ||
string="New Source Location", | ||
related="picking_type_id.default_location_src_id", | ||
) | ||
location_dest_id = fields.Many2one( | ||
string="New Destination Location", | ||
related="picking_type_id.default_location_dest_id", | ||
) | ||
|
||
def change_picking_type(self): | ||
self.ensure_one() | ||
if ( | ||
not self.picking_type_id | ||
or self.picking_type_id == self.old_picking_type_id | ||
): | ||
return | ||
if not self.picking_id.change_picking_type_enabled: | ||
raise ValidationError(_( | ||
"Cannot change Operation Type for %s because is" | ||
" not allowed due to its current state" | ||
) % self.picking_id.name) | ||
|
||
self.picking_id.write({ | ||
"picking_type_id": self.picking_type_id.id, | ||
"location_id": self.location_id.id, | ||
"location_dest_id": self.location_dest_id.id, | ||
}) | ||
|
||
wiz_change = self.env["stock.move.change.source.location.wizard"].with_context( | ||
active_ids=self.picking_id.ids, active_model="stock.picking" | ||
).create({ | ||
"new_location_id": self.picking_id.location_id.id, | ||
"moves_to_change": "all", | ||
}) | ||
ret = wiz_change.action_apply() | ||
msg = _("Operation Type moved from %s to %s") % ( | ||
self.old_picking_type_id.display_name, self.picking_type_id.display_name | ||
) | ||
self.picking_id.message_post(body=msg) | ||
|
||
return ret |
62 changes: 62 additions & 0 deletions
62
...k_picking_out_change_picking_type/wizards/stock_picking_out_change_picking_type_views.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<record id="view_stock_return_picking_ls_wizard" model="ir.ui.view"> | ||
<field name="name">stock.picking.out.change.picking.type.wizard.form</field> | ||
<field name="model">stock.picking.out.change.picking.type.wizard</field> | ||
<field name="arch" type="xml"> | ||
<form> | ||
<sheet> | ||
<group> | ||
<group> | ||
<field name="old_picking_type_id" /> | ||
<field name="picking_id" /> | ||
</gruop> | ||
<group> | ||
<field name="company_id" invisible="1" /> | ||
<field | ||
name="picking_type_id" | ||
domain="[ | ||
('company_id', '=', company_id), | ||
('id', '!=', old_picking_type_id), | ||
]" | ||
required="True" | ||
/> | ||
<field | ||
name="location_id" | ||
atrrs="{'invisible': [('picking_type_id', '=', False)]}" | ||
/> | ||
<field | ||
name="location_dest_id" | ||
atrrs="{'invisible': [('picking_type_id', '=', False)]}" | ||
/> | ||
</gruop> | ||
</gruop> | ||
<group attrs="{'invisible': [('picking_type_id', '=', False)]}"> | ||
<p> | ||
Operation Type for selected picking will change, | ||
but its number will remain the same within old | ||
Operation Type sequence. Are you sure? | ||
</p> | ||
</group> | ||
<footer> | ||
<button | ||
name="change_picking_type" | ||
id="button_change_picking_type" | ||
string="Apply" | ||
type="object" | ||
class="oe_highlight" | ||
/> | ||
<button string="Cancel" class="btn-secondary" special="cancel"/> | ||
</footer> | ||
</sheet> | ||
</form> | ||
</field> | ||
</record> | ||
|
||
<record id="action_stock_picking_change_picking_type" model="ir.actions.act_window"> | ||
<field name="name">Change Picking Operation</field> | ||
<field name="res_model">stock.picking.out.change.picking.type.wizard</field> | ||
<field name="view_mode">form</field> | ||
<field name="target">new</field> | ||
</record> | ||
</odoo> |