diff --git a/addons/sale_project_stock/__init__.py b/addons/sale_project_stock/__init__.py new file mode 100644 index 00000000000..dc5e6b693d1 --- /dev/null +++ b/addons/sale_project_stock/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import models diff --git a/addons/sale_project_stock/__manifest__.py b/addons/sale_project_stock/__manifest__.py new file mode 100644 index 00000000000..00216dceb69 --- /dev/null +++ b/addons/sale_project_stock/__manifest__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +{ + 'name': 'Sale Project - Sale Stock', + 'version': '1.0', + 'description': 'Adds a full traceability of inventory operations on the profitability report.', + 'summary': 'Adds a full traceability of inventory operations on the profitability report.', + 'license': 'LGPL-3', + 'category': 'Sales', + 'depends': ['sale_project', 'sale_stock'], + 'data': [ + 'views/stock_move_views.xml', + ], + 'demo': [], + 'auto_install': True, + 'application': False, +} diff --git a/addons/sale_project_stock/models/__init__.py b/addons/sale_project_stock/models/__init__.py new file mode 100644 index 00000000000..83c06ee1343 --- /dev/null +++ b/addons/sale_project_stock/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import sale_order_line diff --git a/addons/sale_project_stock/models/sale_order_line.py b/addons/sale_project_stock/models/sale_order_line.py new file mode 100644 index 00000000000..5008b7395d1 --- /dev/null +++ b/addons/sale_project_stock/models/sale_order_line.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models + +class SaleOrderLine(models.Model): + _inherit = 'sale.order.line' + + # FIXME: see if we move this computed field into sale_stock module. + stock_move_count = fields.Integer(compute='_compute_stock_move_count') + + @api.depends('move_ids') + def _compute_stock_move_count(self): + stock_move_read_group = self.env['stock.move'].read_group([('sale_line_id', 'in', self.ids)], ['sale_line_id'], ['sale_line_id']) + stock_move_count_per_sol = {res['sale_line_id'][0]: res['sale_line_id_count'] for res in stock_move_read_group} + for sol in self: + sol.stock_move_count = stock_move_count_per_sol.get(sol.id, 0) + + def _get_action_per_item(self): + """ Get action per Sales Order Item to display the stock moves linked + + :returns: Dict containing id of SOL as key and the action as value + """ + action_per_sol = super()._get_action_per_item() + stock_move_action = self.env.ref('sale_project_stock.stock_move_per_sale_order_line_action').id + for sol in self: + if not sol.is_service and sol.stock_move_count > 0: + action_per_sol[sol.id] = stock_move_action + return action_per_sol diff --git a/addons/sale_project_stock/views/stock_move_views.xml b/addons/sale_project_stock/views/stock_move_views.xml new file mode 100644 index 00000000000..7edd1ef3b9b --- /dev/null +++ b/addons/sale_project_stock/views/stock_move_views.xml @@ -0,0 +1,22 @@ + + + + + Transfers + stock.move + tree,kanban,pivot,graph,form + [('sale_line_id', '=', active_id)] + {} + +

+ No stock move found +

+

+ This menu gives you the full traceability of inventory + operations on a specific product. You can filter on the product + to see all the past or future movements for the product. +

+
+
+ +