diff --git a/stock_landed_cost_internal_transfer/__init__.py b/stock_landed_cost_internal_transfer/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/stock_landed_cost_internal_transfer/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_landed_cost_internal_transfer/__manifest__.py b/stock_landed_cost_internal_transfer/__manifest__.py new file mode 100644 index 000000000..780b5a846 --- /dev/null +++ b/stock_landed_cost_internal_transfer/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright (C) 2024 Open Source Integrators +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). +{ + "name": "Stock Landed Cost Internal Transfer", + "summary": "Stock Landed Cost Internal Transfer", + "category": "Stock", + "website": "https://github.com/ursais/osi-addons", + "author": "Open Source Integrators", + "maintainer": "Open Source Integrators", + "version": "17.0.1.0.0", + "license": "LGPL-3", + "depends": ["stock_landed_costs"], + "data": [ + "views/stock_picking_view.xml" + ], +} diff --git a/stock_landed_cost_internal_transfer/models/__init__.py b/stock_landed_cost_internal_transfer/models/__init__.py new file mode 100644 index 000000000..ae4c27227 --- /dev/null +++ b/stock_landed_cost_internal_transfer/models/__init__.py @@ -0,0 +1 @@ +from . import stock_picking diff --git a/stock_landed_cost_internal_transfer/models/stock_picking.py b/stock_landed_cost_internal_transfer/models/stock_picking.py new file mode 100644 index 000000000..72ef7643a --- /dev/null +++ b/stock_landed_cost_internal_transfer/models/stock_picking.py @@ -0,0 +1,40 @@ +from odoo import api, fields, models + + +class StockPicking(models.Model): + _inherit = 'stock.picking' + + is_cost_based_transfer = fields.Boolean(copy=False) + orig_dest_location_id = fields.Many2one('stock.location', copy=False) + new_picking_id = fields.Many2one('stock.picking') + + @api.onchange('is_cost_based_transfer') + def _onchange_cost_based_transfer(self): + if self.is_cost_based_transfer: + self.location_dest_id = self.env.ref('stock.stock_location_inter_wh').id + self.move_ids.location_dest_id = self.env.ref('stock.stock_location_inter_wh').id + + def _action_done(self): + res = super()._action_done() + # Create a new picking and update locations for 'Cost based transfer'. + if not self._context.get('skip_cost_based_transfer'): + for picking in self.filtered(lambda p: p.is_cost_based_transfer and p.picking_type_code == 'internal'): + new_in_picking = picking.copy() + picking.new_picking_id = new_in_picking.id + new_in_picking.location_id = self.env.ref('stock.stock_location_inter_wh').id + new_in_picking.location_dest_id = picking.orig_dest_location_id + new_in_picking.move_ids.location_dest_id = picking.orig_dest_location_id + new_in_picking.action_confirm() + new_in_picking.action_assign() + new_in_picking.with_context(skip_cost_based_transfer=1, button_validate_picking_ids=new_in_picking.ids).button_validate() + return res + + def view_new_picking(self): + action = self.env["ir.actions.actions"]._for_xml_id("stock.action_picking_tree_all") + form_view = [(self.env.ref('stock.view_picking_form').id, 'form')] + if 'views' in action: + action['views'] = form_view + [(state, view) for state, view in action['views'] if view != 'form'] + else: + action['views'] = form_view + action['res_id'] = self.new_picking_id.id + return action diff --git a/stock_landed_cost_internal_transfer/views/stock_picking_view.xml b/stock_landed_cost_internal_transfer/views/stock_picking_view.xml new file mode 100644 index 000000000..9958cd0ee --- /dev/null +++ b/stock_landed_cost_internal_transfer/views/stock_picking_view.xml @@ -0,0 +1,25 @@ + + + + view.picking.form.inherit.add.lc.fields + stock.picking + + + + + + + + is_cost_based_transfer + 1 + + + + + + + +