-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD]sale_procurement_group_by_requested_date_sale_sourced_by_line. G…
…lue module.
- Loading branch information
1 parent
95fa3c2
commit b2e78f2
Showing
9 changed files
with
280 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
sale_procurement_group_by_requested_date_sale_sourced_by_line/README.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg | ||
:alt: License: AGPL-3 | ||
|
||
============================================================= | ||
Sale Procurement Group by Requested date Sale Sourced by line | ||
============================================================= | ||
|
||
This is a glue module. It makes source_procurement_group_by_requested_date | ||
compatible with sale_sourced_by_line | ||
|
||
|
||
Usage | ||
===== | ||
|
||
|
||
.. 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/10.0 | ||
|
||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback | ||
|
||
Credits | ||
======= | ||
|
||
Contributors | ||
------------ | ||
|
||
* Aaron Henriquez <[email protected]> | ||
* Jordi Ballester <[email protected]> | ||
* Darshan Patel <[email protected]> | ||
|
||
Maintainer | ||
---------- | ||
|
||
.. image:: http://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: http://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 http://odoo-community.org. |
6 changes: 6 additions & 0 deletions
6
sale_procurement_group_by_requested_date_sale_sourced_by_line/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
# Copyright 2017 Serpent Consulting Services Pvt. Ltd. | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import models |
21 changes: 21 additions & 0 deletions
21
sale_procurement_group_by_requested_date_sale_sourced_by_line/__manifest__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Eficent Business and IT Consulting Services S.L. | ||
# Copyright 2017 Serpent Consulting Services Pvt. Ltd. | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
{ | ||
"name": "Group procurements by source wh and requested date", | ||
"summary": "Integrates sale_source_by_line and sale procurement group", | ||
"version": "10.0.1.0.0", | ||
"category": "Sales Management", | ||
'website': "https://github.com/OCA/sale-workflow", | ||
"author": "Eficent , " | ||
"Odoo Community Association (OCA)", | ||
"license": "AGPL-3", | ||
"depends": [ | ||
"sale_sourced_by_line", | ||
"sale_procurement_group_by_requested_date", | ||
], | ||
"installable": True, | ||
"auto_install": True, | ||
} |
6 changes: 6 additions & 0 deletions
6
sale_procurement_group_by_requested_date_sale_sourced_by_line/models/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
# Copyright 2017 Serpent Consulting Services Pvt. Ltd. | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import sale_order |
48 changes: 48 additions & 0 deletions
48
sale_procurement_group_by_requested_date_sale_sourced_by_line/models/sale_order.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Eficent Business and IT Consulting Services S.L. | ||
# Copyright 2017 Serpent Consulting Services Pvt. Ltd. | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class SaleOrder(models.Model): | ||
_inherit = 'sale.order' | ||
|
||
@api.model | ||
def _prepare_procurement_group_by_line(self, line): | ||
# for compatibility with sale_quotation_sourcing | ||
vals = super(SaleOrder, self)._prepare_procurement_group_by_line(line) | ||
req_datetime = fields.Datetime.from_string(line.requested_date) | ||
req_date = fields.Date.to_string(req_datetime) | ||
if line._get_procurement_group_key()[0] == 14: | ||
if line.requested_date and line.warehouse_id: | ||
vals['name'] = '/'.join([vals['name'], line.warehouse_id.name, | ||
req_date]) | ||
return vals | ||
|
||
|
||
class SaleOrderLine(models.Model): | ||
_inherit = 'sale.order.line' | ||
|
||
@api.multi | ||
def _get_procurement_group_key(self): | ||
""" Return a key with priority to be used to regroup lines in multiple | ||
procurement groups. The higher the priority number is the more | ||
preference the criteria has. E.g. sale_sourced_by_line has 10 priority, | ||
that is less priority than the requested date. | ||
""" | ||
priority = 14 | ||
key = super(SaleOrderLine, self)._get_procurement_group_key() | ||
# Check priority | ||
if key[0] >= priority: | ||
return key | ||
req_datetime = fields.Datetime.from_string(self.requested_date) | ||
req_date = fields.Date.to_string(req_datetime) | ||
if self.warehouse_id and not req_date: | ||
return (priority, self.warehouse_id.id) | ||
if req_date and not self.warehouse_id: | ||
return (priority, str(req_date)) | ||
if self.warehouse_id and req_date: | ||
key = '/'.join([str(self.warehouse_id.id), req_date]) | ||
return (priority, key) |
6 changes: 6 additions & 0 deletions
6
sale_procurement_group_by_requested_date_sale_sourced_by_line/tests/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
# Copyright 2017 Serpent Consulting Services Pvt. Ltd. | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import test_sale |
127 changes: 127 additions & 0 deletions
127
sale_procurement_group_by_requested_date_sale_sourced_by_line/tests/test_sale.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Eficent Business and IT Consulting Services S.L. | ||
# Copyright 2017 Serpent Consulting Services Pvt. Ltd. | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo.tests.common import TransactionCase | ||
from odoo import fields | ||
import datetime | ||
|
||
|
||
class TestSaleMultiPickingByRequestedDate(TransactionCase): | ||
"""Check the _get_shipped method of Sale Order. """ | ||
|
||
def setUp(self): | ||
"""Setup a Sale Order with 4 lines. | ||
And prepare procurements | ||
""" | ||
super(TestSaleMultiPickingByRequestedDate, self).setUp() | ||
sale_obj = self.env['sale.order'] | ||
order_line = self.env['sale.order.line'] | ||
Product = self.env['product.product'] | ||
Warehouse = self.env['stock.warehouse'] | ||
self.wh1 = Warehouse.create({'name': 'wh1', 'code': 'wh1'}) | ||
self.wh2 = Warehouse.create({'name': 'wh2', 'code': 'wh2'}) | ||
p1 = Product.create({'name': 'p1', 'type': 'product'}).id | ||
today = datetime.datetime.now() | ||
self.dt1 = today | ||
self.dt2 = today + datetime.timedelta(days=1) | ||
|
||
self.sale1 = sale_obj.create({'partner_id': 1}) | ||
self.sale_line1 = order_line.create({ | ||
'product_id': p1, | ||
'name': 'cool product', | ||
'order_id': self.sale1.id, | ||
'warehouse_id': self.wh1.id, | ||
'requested_date': self.dt1 | ||
}) | ||
self.sale_line2 = order_line.create({ | ||
'product_id': p1, | ||
'name': 'cool product', | ||
'order_id': self.sale1.id, | ||
'warehouse_id': self.wh1.id, | ||
'requested_date': self.dt2 | ||
}) | ||
self.sale_line3 = order_line.create({ | ||
'product_id': p1, | ||
'name': 'cool product', | ||
'order_id': self.sale1.id, | ||
'warehouse_id': self.wh2.id, | ||
'requested_date': self.dt1 | ||
}) | ||
self.sale_line4 = order_line.create({ | ||
'product_id': p1, | ||
'name': 'cool product', | ||
'order_id': self.sale1.id, | ||
'warehouse_id': self.wh2.id, | ||
'requested_date': self.dt2 | ||
}) | ||
|
||
self.sale2 = sale_obj.create({'partner_id': 1}) | ||
self.sale_line5 = order_line.create({ | ||
'product_id': p1, | ||
'name': 'cool product', | ||
'order_id': self.sale2.id, | ||
'warehouse_id': self.wh1.id, | ||
'requested_date': self.dt1 | ||
}) | ||
self.sale_line6 = order_line.create({ | ||
'product_id': p1, | ||
'name': 'cool product', | ||
'order_id': self.sale2.id, | ||
'warehouse_id': self.wh1.id, | ||
'requested_date': self.dt2 | ||
}) | ||
self.sale_line7 = order_line.create({ | ||
'product_id': p1, | ||
'name': 'cool product', | ||
'order_id': self.sale2.id, | ||
'warehouse_id': self.wh1.id, | ||
'requested_date': self.dt1 | ||
}) | ||
self.sale_line8 = order_line.create({ | ||
'product_id': p1, | ||
'name': 'cool product', | ||
'order_id': self.sale2.id, | ||
'warehouse_id': self.wh1.id, | ||
'requested_date': self.dt2 | ||
}) | ||
|
||
def test_number_of_groups(self): | ||
"""True when the number of groups created matches the | ||
result of multiply the different warehouses with the different | ||
requested dates""" | ||
ok = False | ||
self.sale1.action_confirm() | ||
req_date = fields.Date.to_string(self.dt1) | ||
g_name = self.sale1.name + '/' + self.wh1.name + '/' + req_date | ||
groups = self.env['procurement.group'].search([('name', '=', g_name)]) | ||
|
||
for group in groups: | ||
if group.name == g_name: | ||
procurements = self.env['procurement.order'].search([ | ||
('group_id', '=', group.id)]) | ||
self.assertEqual(len(procurements), 1) | ||
self.assertEqual(len(group), 1) | ||
ok = True | ||
self.assertTrue(ok) | ||
|
||
ok = False | ||
self.sale2.action_confirm() | ||
req_date = fields.Date.to_string(self.dt2) | ||
g_name = self.sale2.name + '/' + self.wh1.name + '/' + req_date | ||
groups = self.env['procurement.group'].search([('name', '=', g_name)]) | ||
|
||
for group in groups: | ||
if group.name == g_name: | ||
procurements = self.env['procurement.order'].search([ | ||
('group_id', '=', group.id)]) | ||
self.assertEqual(len(procurements), 2) | ||
self.assertEqual(len(group), 1) | ||
ok = True | ||
self.assertEqual(len(groups), 1) | ||
g_name = self.sale2.name + '/' + self.wh1.name + '/' | ||
groups = self.env['procurement.group'].search([('name', 'ilike', | ||
g_name)]) | ||
self.assertEqual(len(groups), 2) | ||
self.assertTrue(ok) |