Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD]stock_landed_cost_internal_transfer #850

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions stock_landed_cost_internal_transfer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
16 changes: 16 additions & 0 deletions stock_landed_cost_internal_transfer/__manifest__.py
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"
],
}
1 change: 1 addition & 0 deletions stock_landed_cost_internal_transfer/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import stock_picking
40 changes: 40 additions & 0 deletions stock_landed_cost_internal_transfer/models/stock_picking.py
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 stock_landed_cost_internal_transfer/views/stock_picking_view.xml
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>
Loading