From cfd3e6b36919c51d366c6a7b54243dfa805e9e64 Mon Sep 17 00:00:00 2001 From: Nicolas Vannieuwerburgh Date: Mon, 11 Jun 2018 11:10:48 +0200 Subject: [PATCH] [IMP] sale_stock: Compute the related sales orders on production lots Add a computed field on a stock.production.lot to retrieve all the sales orders coming from a done stock.move.line if the stock.move is also done and if the destination usage is 'customer'. --- addons/sale_stock/__manifest__.py | 1 + addons/sale_stock/models/stock.py | 15 +++++++ .../views/stock_production_lot_views.xml | 41 +++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 addons/sale_stock/views/stock_production_lot_views.xml diff --git a/addons/sale_stock/__manifest__.py b/addons/sale_stock/__manifest__.py index 77a181a7195..ec0f0daa5d0 100644 --- a/addons/sale_stock/__manifest__.py +++ b/addons/sale_stock/__manifest__.py @@ -36,6 +36,7 @@ You can choose flexible invoicing methods: 'views/sale_stock_portal_template.xml', 'views/product_template_views.xml', 'views/res_users_views.xml', + 'views/stock_production_lot_views.xml', 'report/sale_order_report_templates.xml', 'report/stock_report_deliveryslip.xml', 'data/sale_stock_data.xml', diff --git a/addons/sale_stock/models/stock.py b/addons/sale_stock/models/stock.py index f42bc1b3a0d..6619f9ae9ff 100644 --- a/addons/sale_stock/models/stock.py +++ b/addons/sale_stock/models/stock.py @@ -101,3 +101,18 @@ class StockPicking(models.Model): self._log_activity(_render_note_exception_quantity, documents) return super(StockPicking, self)._log_less_quantities_than_expected(moves) + +class ProductionLot(models.Model): + _inherit = 'stock.production.lot' + + sale_order_ids = fields.Many2many('sale.order', string="Sales Orders", compute='_compute_sale_order_ids') + + @api.depends('name') + def _compute_sale_order_ids(self): + for lot in self: + stock_moves = self.env['stock.move.line'].search([ + ('lot_id', '=', lot.id), + ('state', '=', 'done') + ]).mapped('move_id').filtered( + lambda move: move.picking_id.location_dest_id.usage == 'customer' and move.state == 'done') + lot.sale_order_ids = stock_moves.mapped('sale_line_id.order_id') diff --git a/addons/sale_stock/views/stock_production_lot_views.xml b/addons/sale_stock/views/stock_production_lot_views.xml new file mode 100644 index 00000000000..e919bb81b9f --- /dev/null +++ b/addons/sale_stock/views/stock_production_lot_views.xml @@ -0,0 +1,41 @@ + + + + stock.production.lot.view.form + stock.production.lot + + + + + + + + + + + + + + + + + + stock.production.lot.view.form.simple + stock.production.lot + + + + + + + + + + + + + + + + +