Skip to content

Commit

Permalink
Add button on top right to link to transit moves on sale and purchase…
Browse files Browse the repository at this point in the history
…s forms
  • Loading branch information
yvaucher authored and gurneyalex committed Apr 9, 2015
1 parent 637a019 commit 630f115
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 0 deletions.
2 changes: 2 additions & 0 deletions stock_shipment_management/__openerp__.py
Expand Up @@ -43,6 +43,8 @@
"view/menu.xml",
"view/shipment_plan.xml",
"view/stock_move.xml",
"view/sale_order.xml",
"view/purchase_order.xml",
"workflow/shipment_plan.xml",
"security/ir.model.access.csv",
],
Expand Down
2 changes: 2 additions & 0 deletions stock_shipment_management/model/__init__.py
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
from . import stock_move
from . import shipment_plan
from . import sale_order
from . import purchase_order
52 changes: 52 additions & 0 deletions stock_shipment_management/model/purchase_order.py
@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
#
#
# Author: Yannick Vaucher
# Copyright 2015 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more description.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
from openerp import models, fields, api


class PurchaseOrder(models.Model):
_inherit = 'purchase.order'

to_transit_moves_count = fields.Integer(
compute='_count_to_transit_moves'
)

@api.multi
def _get_to_transit_moves(self):
""" Get moves related to Purchase order going to transit location"""
moves = self.picking_ids.mapped('move_lines')
return moves.filtered(
lambda rec: rec.location_dest_id.usage == 'transit')

@api.one
@api.depends('picking_ids.move_lines.location_dest_id.usage')
def _count_to_transit_moves(self):
""" Count moves related to Purchase order going to transit location"""
self.to_transit_moves_count = len(self._get_to_transit_moves())

@api.multi
def action_open_to_transit_moves(self):
""" Open move list view of to transit moves """
action_ref = ('stock_shipment_management'
'.action_move_transit_pipeline_waiting')
action_dict = self.env.ref(action_ref).read()[0]
moves = self._get_to_transit_moves()
action_dict['domain'] = [('id', 'in', moves.ids)]
return action_dict
52 changes: 52 additions & 0 deletions stock_shipment_management/model/sale_order.py
@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
#
#
# Author: Yannick Vaucher
# Copyright 2015 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more description.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
from openerp import models, fields, api


class SaleOrder(models.Model):
_inherit = 'sale.order'

to_transit_moves_count = fields.Integer(
compute='_count_to_transit_moves'
)

@api.multi
def _get_to_transit_moves(self):
""" Get moves related to Sale order going to transit location"""
moves = self.picking_ids.mapped('move_lines')
return moves.filtered(
lambda rec: rec.location_dest_id.usage == 'transit')

@api.one
@api.depends('picking_ids.move_lines.location_dest_id.usage')
def _count_to_transit_moves(self):
""" Count moves related to Sale order going to transit location"""
self.to_transit_moves_count = len(self._get_to_transit_moves())

@api.multi
def action_open_to_transit_moves(self):
""" Open move list view of to transit moves """
action_ref = ('stock_shipment_management'
'.action_move_transit_pipeline_waiting')
action_dict = self.env.ref(action_ref).read()[0]
moves = self._get_to_transit_moves()
action_dict['domain'] = [('id', 'in', moves.ids)]
return action_dict
20 changes: 20 additions & 0 deletions stock_shipment_management/view/purchase_order.xml
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="purchase_order_form_2_in_transit_moves" model="ir.ui.view">
<field name="name">purchase.order.form</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_2_stock_picking"/>
<field name="arch" type="xml">

<xpath expr="//div[@name='buttons']" position="inside">
<button class="oe_inline oe_stat_button" name="action_open_to_transit_moves"
type="object" icon="fa-upload">
<field string="To transit moves" name="to_transit_moves_count" widget="statinfo" />
</button>
</xpath>

</field>
</record>
</data>
</openerp>
22 changes: 22 additions & 0 deletions stock_shipment_management/view/sale_order.xml
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_order_form" model="ir.ui.view">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">

<h1 position="before">
<div class="oe_right oe_button_box" style="width: 300px;" name="buttons">
<button class="oe_inline oe_stat_button" name="action_open_to_transit_moves"
type="object" icon="fa-upload">
<field string="To transit moves" name="to_transit_moves_count" widget="statinfo" />
</button>
</div>
</h1>

</field>
</record>
</data>
</openerp>

0 comments on commit 630f115

Please sign in to comment.