From 630f115995e99926e0ae472603cabf2c78567220 Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Thu, 2 Apr 2015 13:40:38 +0200 Subject: [PATCH] Add button on top right to link to transit moves on sale and purchases forms --- stock_shipment_management/__openerp__.py | 2 + stock_shipment_management/model/__init__.py | 2 + .../model/purchase_order.py | 52 +++++++++++++++++++ stock_shipment_management/model/sale_order.py | 52 +++++++++++++++++++ .../view/purchase_order.xml | 20 +++++++ stock_shipment_management/view/sale_order.xml | 22 ++++++++ 6 files changed, 150 insertions(+) create mode 100644 stock_shipment_management/model/purchase_order.py create mode 100644 stock_shipment_management/model/sale_order.py create mode 100644 stock_shipment_management/view/purchase_order.xml create mode 100644 stock_shipment_management/view/sale_order.xml diff --git a/stock_shipment_management/__openerp__.py b/stock_shipment_management/__openerp__.py index 3ec2482f..e4582e53 100644 --- a/stock_shipment_management/__openerp__.py +++ b/stock_shipment_management/__openerp__.py @@ -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", ], diff --git a/stock_shipment_management/model/__init__.py b/stock_shipment_management/model/__init__.py index ba122fc5..7252b46e 100644 --- a/stock_shipment_management/model/__init__.py +++ b/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 diff --git a/stock_shipment_management/model/purchase_order.py b/stock_shipment_management/model/purchase_order.py new file mode 100644 index 00000000..02adc8b7 --- /dev/null +++ b/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 . +# +# +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 diff --git a/stock_shipment_management/model/sale_order.py b/stock_shipment_management/model/sale_order.py new file mode 100644 index 00000000..74f72649 --- /dev/null +++ b/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 . +# +# +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 diff --git a/stock_shipment_management/view/purchase_order.xml b/stock_shipment_management/view/purchase_order.xml new file mode 100644 index 00000000..f3a53f48 --- /dev/null +++ b/stock_shipment_management/view/purchase_order.xml @@ -0,0 +1,20 @@ + + + + + purchase.order.form + purchase.order + + + + + + + + + + + diff --git a/stock_shipment_management/view/sale_order.xml b/stock_shipment_management/view/sale_order.xml new file mode 100644 index 00000000..aa97bdc2 --- /dev/null +++ b/stock_shipment_management/view/sale_order.xml @@ -0,0 +1,22 @@ + + + + + sale.order.form + sale.order + + + +

+
+ +
+

+ +
+
+
+