Skip to content

Commit

Permalink
[ADD]sale_procurement_group_by_requested_date_sale_sourced_by_line. G…
Browse files Browse the repository at this point in the history
…lue module.
  • Loading branch information
AaronHForgeFlow committed Mar 21, 2019
1 parent 95fa3c2 commit b2e78f2
Show file tree
Hide file tree
Showing 9 changed files with 280 additions and 2 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ env:
- TRANSIFEX="1"
- TESTS="1" ODOO_REPO="odoo/odoo" LINT_CHECK="0" EXCLUDE=sale_procurement_group_by_requested_date_sale_sourced_by_line,sale_procurement_group_by_requested_date,sale_delivery_split_date,sale_stock_picking_blocking_proc_group_by_line,sale_sourced_by_line,sale_procurement_group_by_line
- TESTS="1" ODOO_REPO="OCA/OCB" LINT_CHECK="0" EXCLUDE=sale_procurement_group_by_requested_date_sale_sourced_by_line,sale_procurement_group_by_requested_date,sale_delivery_split_date,sale_stock_picking_blocking_proc_group_by_line,sale_sourced_by_line,sale_procurement_group_by_line
- TESTS="1" ODOO_REPO="odoo/odoo" LINT_CHECK="0" INCLUDE=sale_procurement_group_by_requested_date_sale_sourced_by_line,sale_procurement_group_by_requested_date,sale_delivery_split_date,sale_stock_picking_blocking_proc_group_by_line,sale_sourced_by_line,sale_procurement_group_by_line
- TESTS="1" ODOO_REPO="OCA/OCB" LINT_CHECK="0" INCLUDE=sale_procurement_group_by_requested_date_sale_sourced_by_line,sale_procurement_group_by_requested_date,sale_delivery_split_date,sale_stock_picking_blocking_proc_group_by_line,sale_sourced_by_line,sale_procurement_group_by_line
- TESTS="1" ODOO_REPO="odoo/odoo" LINT_CHECK="0" INCLUDE=sale_delivery_split_date,sale_stock_picking_blocking_proc_group_by_line,sale_sourced_by_line,sale_procurement_group_by_line
- TESTS="1" ODOO_REPO="OCA/OCB" LINT_CHECK="0" INCLUDE=sale_delivery_split_date,sale_stock_picking_blocking_proc_group_by_line,sale_sourced_by_line,sale_procurement_group_by_line
- TESTS="1" ODOO_REPO="odoo/odoo" LINT_CHECK="0" INCLUDE=sale_procurement_group_by_requested_date_sale_sourced_by_line,sale_procurement_group_by_requested_date,sale_stock_picking_blocking_proc_group_by_line,sale_sourced_by_line,sale_procurement_group_by_line
- TESTS="1" ODOO_REPO="OCA/OCB" LINT_CHECK="0" INCLUDE=sale_procurement_group_by_requested_date_sale_sourced_by_line,sale_procurement_group_by_requested_date,sale_stock_picking_blocking_proc_group_by_line,sale_sourced_by_line,sale_procurement_group_by_line

virtualenv:
system_site_packages: true
Expand Down
11 changes: 11 additions & 0 deletions sale_procurement_group_by_requested_date/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ Usage
:target: https://runbot.odoo-community.org/runbot/167/10.0


Known issues / Roadmap
======================

This module is compatible with sale_sourced_by_line module by installing
sale_procurement_group_by_requested_date_sale_sourced_by_line. This module
is not compatible with sale_delivery_split_date. A glue module will be needed
to install sale_delivery_split_date and
sale_procurement_group_by_requested_date. This is an already known issue:
https://github.com/OCA/sale-workflow/issues/717#issuecomment-430231334


Bug Tracker
===========

Expand Down
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.
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
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,
}
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
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)
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
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)

0 comments on commit b2e78f2

Please sign in to comment.