Skip to content

Commit

Permalink
[FIX] make sale_delivery_block compatible with sale_procurement_group…
Browse files Browse the repository at this point in the history
…_by_line
  • Loading branch information
JordiBForgeFlow authored and LoisRForgeFlow committed Mar 24, 2017
1 parent 731a28c commit d9e3f95
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 8 deletions.
5 changes: 5 additions & 0 deletions sale_delivery_block/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
70 changes: 70 additions & 0 deletions sale_delivery_block_proc_group_by_line/README.rst
Original file line number Diff line number Diff line change
@@ -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
<https://github.com/OCA/purchase-workflow/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 <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

Contributors
------------

* Lois Rilo <lois.rilo@eficent.com>

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.
6 changes: 6 additions & 0 deletions sale_delivery_block_proc_group_by_line/__init__.py
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions sale_delivery_block_proc_group_by_line/__openerp__.py
Original file line number Diff line number Diff line change
@@ -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,
}
6 changes: 6 additions & 0 deletions sale_delivery_block_proc_group_by_line/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions sale_delivery_block_proc_group_by_line/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -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
23 changes: 15 additions & 8 deletions sale_procurement_group_by_line/model/sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand All @@ -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',
Expand Down

0 comments on commit d9e3f95

Please sign in to comment.