-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #850 from ursais/lc_internal_transfer
[ADD]stock_landed_cost_internal_transfer
- Loading branch information
Showing
5 changed files
with
83 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 @@ | ||
from . import models |
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,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" | ||
], | ||
} |
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 |
40 changes: 40 additions & 0 deletions
40
stock_landed_cost_internal_transfer/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,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 |
25 changes: 25 additions & 0 deletions
25
stock_landed_cost_internal_transfer/views/stock_picking_view.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,25 @@ | ||
<odoo> | ||
|
||
<record id="view_picking_form_inherit_add_lc_fields" model="ir.ui.view"> | ||
<field name="name">view.picking.form.inherit.add.lc.fields</field> | ||
<field name="model">stock.picking</field> | ||
<field name="inherit_id" ref="stock.view_picking_form"/> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//field[@name='origin']" position="after"> | ||
<field name="is_cost_based_transfer" invisible="picking_type_code != 'internal'" readonly="state in ['done', 'cancel']"/> | ||
<field name="orig_dest_location_id" required="is_cost_based_transfer" invisible="not is_cost_based_transfer" readonly="state in ['done', 'cancel']"/> | ||
</xpath> | ||
<xpath expr="//field[@name='location_dest_id'][2]" position="attributes"> | ||
<attribute name="readonly">is_cost_based_transfer</attribute> | ||
<attribute name="force_save">1</attribute> | ||
</xpath> | ||
<xpath expr="//div[@name='button_box']" position="inside"> | ||
<field name="new_picking_id" invisible="1"/> | ||
<button name="view_new_picking" type="object" class="oe_stat_button" icon="fa-truck" | ||
invisible="not new_picking_id"> | ||
<span class="o_stat_text">IN Picking</span> | ||
</button> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |