diff --git a/sale_delivery_block/models/sale_order.py b/sale_delivery_block/models/sale_order.py index c0c9b99577e..bda0274eaa5 100644 --- a/sale_delivery_block/models/sale_order.py +++ b/sale_delivery_block/models/sale_order.py @@ -38,6 +38,11 @@ class SaleOrderLine(models.Model): @api.multi def _action_procurement_create(self): new_procs = self.env['procurement.order'] + # When module 'sale_procurement_group_by_line_is installed' we do not + # want to use this method but call super. See module + # 'sale_delivery_block_proc_group_by_line + if 'group_by_line' in self.env.context: + return super(SaleOrderLine, self)._action_procurement_create() for line in self: if not line.order_id.delivery_block_id: new_procs += super(SaleOrderLine, diff --git a/sale_delivery_block_proc_group_by_line/README.rst b/sale_delivery_block_proc_group_by_line/README.rst new file mode 100644 index 00000000000..e4fc4bfc657 --- /dev/null +++ b/sale_delivery_block_proc_group_by_line/README.rst @@ -0,0 +1,70 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +=================== +Sale Delivery Block +=================== + +This module extends the functionality of sales to allow you to block the +creation of deliveries from a sale order and give a reason. + +Configuration +============= + +To configure this module, you need to: + +#. Go to 'Sales > Configuration > Sales > Delivery Block Reason'. +#. Create the different reasons that can lead to block the deliveries of a + sales order. +#. Add some users to the group 'Release Delivery Block in Sales Orders'. + +Usage +===== + +To use this module, you need to: + +#. Create a new sales order and provide a 'Delivery Block Reason'. +#. Confirm Sale (No delivery would be created). +#. Release Delivery Block when it is time to create the deliveries for + the sale order. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/167/9.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smash it by providing detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Lois Rilo + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/sale_delivery_block_proc_group_by_line/__init__.py b/sale_delivery_block_proc_group_by_line/__init__.py new file mode 100644 index 00000000000..e50f9b65687 --- /dev/null +++ b/sale_delivery_block_proc_group_by_line/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/sale_delivery_block_proc_group_by_line/__openerp__.py b/sale_delivery_block_proc_group_by_line/__openerp__.py new file mode 100644 index 00000000000..a40ff68eb07 --- /dev/null +++ b/sale_delivery_block_proc_group_by_line/__openerp__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Sale Delivery Block Procurement Group By Line", + "summary": "Module that allows module sale_delivery_block to work with " + "sale_procurement_group_by_line", + "version": "9.0.1.0.0", + "author": "Eficent, " + "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/sale-workflow", + "category": "Sales", + "depends": [ + "sale_procurement_group_by_line", + "sale_delivery_block" + ], + "auto_install": True, + "license": "AGPL-3", + "installable": True, + "application": False, +} diff --git a/sale_delivery_block_proc_group_by_line/models/__init__.py b/sale_delivery_block_proc_group_by_line/models/__init__.py new file mode 100644 index 00000000000..fdee10bbe1a --- /dev/null +++ b/sale_delivery_block_proc_group_by_line/models/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import sale_order diff --git a/sale_delivery_block_proc_group_by_line/models/sale_order.py b/sale_delivery_block_proc_group_by_line/models/sale_order.py new file mode 100644 index 00000000000..8bd7c153f78 --- /dev/null +++ b/sale_delivery_block_proc_group_by_line/models/sale_order.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from openerp import api, fields, models, _ + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + @api.multi + def _action_procurement_create(self): + new_procs = self.env['procurement.order'] + for line in self: + if not line.order_id.delivery_block_id: + new_procs += super( + SaleOrderLine, line.with_context( + group_by_line=True))._action_procurement_create() + return new_procs diff --git a/sale_procurement_group_by_line/model/sale.py b/sale_procurement_group_by_line/model/sale.py index e49e3fe6bc0..94af53cc9c0 100644 --- a/sale_procurement_group_by_line/model/sale.py +++ b/sale_procurement_group_by_line/model/sale.py @@ -28,15 +28,16 @@ def _compute_get_picking_ids(self): for line in sale.order_line if line.procurement_group_id]) if not any(group_ids): - self.picking_ids = [] + sale.picking_ids = [] continue - self.picking_ids = self.env['stock.picking'].search( + sale.picking_ids = self.env['stock.picking'].search( [('group_id', 'in', list(group_ids))]) + sale.delivery_count = len(sale.picking_ids) - picking_ids = fields.One2many('stock.picking', - compute='_compute_get_picking_ids', - method=True, - string='Picking associated to this sale') + picking_ids = fields.Many2many('stock.picking', + compute='_compute_get_picking_ids', + method=True, + string='Picking associated to this sale') class SaleOrderLine(models.Model): @@ -73,11 +74,16 @@ def _action_procurement_create(self): # Group the sales order lines with same procurement group # according to the group key - group_id = groups.get(line._get_procurement_group_key()) + group_id = line.procurement_group_id or False + for l in line.order_id.order_line: + g_id = l.procurement_group_id or False + if g_id: + groups[l._get_procurement_group_key()] = g_id + if not group_id: + group_id = groups.get(line._get_procurement_group_key()) if not group_id: vals = line.order_id._prepare_procurement_group_by_line(line) group_id = self.env["procurement.group"].create(vals) - groups[line._get_procurement_group_key()] = group_id line.procurement_group_id = group_id vals = line._prepare_order_line_procurement( @@ -86,6 +92,7 @@ def _action_procurement_create(self): new_proc = self.env["procurement.order"].create(vals) new_procs += new_proc new_procs.run() + super(SaleOrderLine, self)._action_procurement_create() return new_procs procurement_group_id = fields.Many2one('procurement.group',