From 2fe84a4df524a6b3a25ddf0d5aa004440a3216d7 Mon Sep 17 00:00:00 2001 From: lreficent Date: Tue, 31 Jan 2017 13:30:21 +0100 Subject: [PATCH] [MIG] sale_stock_operating_unit to v10. --- sale_stock_operating_unit/README.rst | 16 +++++----- sale_stock_operating_unit/__init__.py | 4 +-- .../{__openerp__.py => __manifest__.py} | 8 ++--- sale_stock_operating_unit/models/__init__.py | 10 ++++--- .../models/{sale_stock.py => sale_order.py} | 29 +++---------------- .../models/stock_move.py | 23 +++++++++++++++ .../models/stock_warehouse.py | 23 +++++++++++++++ sale_stock_operating_unit/tests/__init__.py | 4 +-- .../tests/test_sale_stock_operating_unit.py | 6 ++-- 9 files changed, 74 insertions(+), 49 deletions(-) rename sale_stock_operating_unit/{__openerp__.py => __manifest__.py} (73%) rename sale_stock_operating_unit/models/{sale_stock.py => sale_order.py} (66%) create mode 100644 sale_stock_operating_unit/models/stock_move.py create mode 100644 sale_stock_operating_unit/models/stock_warehouse.py diff --git a/sale_stock_operating_unit/README.rst b/sale_stock_operating_unit/README.rst index b2f1e6c901..f9fc7687c0 100644 --- a/sale_stock_operating_unit/README.rst +++ b/sale_stock_operating_unit/README.rst @@ -2,15 +2,13 @@ :target: https://www.gnu.org/licenses/lgpl.html :alt: License: LGPL-3 -=============================== -Operating Unit in Sales -=============================== - -This module was written to extend the Sales capabilities of Odoo. -This module introduces the operating unit to the Sales Order. -Security rules are defined to ensure that users can only display the -Sales Orders in which they are allowed access to. +============================= +Operating Unit in Sales Stock +============================= +This module was written to extend the Sales and the Stock capabilities of Odoo. +This module introduces some new operating unit (OU) capabilities in order to +enhance the performance of already existing OU features for Sales and Stock. Configuration ============= @@ -23,7 +21,7 @@ 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/213/7.0 + :target: https://runbot.odoo-community.org/runbot/213/10.0 Bug Tracker =========== diff --git a/sale_stock_operating_unit/__init__.py b/sale_stock_operating_unit/__init__.py index 747d0698d4..2ac09aec86 100644 --- a/sale_stock_operating_unit/__init__.py +++ b/sale_stock_operating_unit/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# © 2015 Eficent Business and IT Consulting Services S.L. - +# © 2015-17 Eficent Business and IT Consulting Services S.L. - # Jordi Ballester Alomar -# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# © 2015-17 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import models diff --git a/sale_stock_operating_unit/__openerp__.py b/sale_stock_operating_unit/__manifest__.py similarity index 73% rename from sale_stock_operating_unit/__openerp__.py rename to sale_stock_operating_unit/__manifest__.py index d3639b0f7e..87c94071e9 100644 --- a/sale_stock_operating_unit/__openerp__.py +++ b/sale_stock_operating_unit/__manifest__.py @@ -1,18 +1,18 @@ # -*- coding: utf-8 -*- -# © 2015 Eficent Business and IT Consulting Services S.L. - +# © 2015-17 Eficent Business and IT Consulting Services S.L. - # Jordi Ballester Alomar -# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# © 2015-17 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). { "name": "Operating Unit in Sales Stock", "summary": "An operating unit (OU) is an organizational entity part of a " "company", - "version": "9.0.1.0.0", + "version": "10.0.1.0.0", "author": "Eficent, Serpent Consulting Services Pvt. Ltd., " "Odoo Community Association (OCA)", "license": "LGPL-3", - "website": "http://www.eficent.com", + "website": "https://github.com/OCA/operating-unit", "category": "Sales Management", "depends": [ "sale_stock", diff --git a/sale_stock_operating_unit/models/__init__.py b/sale_stock_operating_unit/models/__init__.py index 94e2800aa5..165f269659 100644 --- a/sale_stock_operating_unit/models/__init__.py +++ b/sale_stock_operating_unit/models/__init__.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- -# © 2015 Eficent Business and IT Consulting Services S.L. - +# © 2015-17 Eficent Business and IT Consulting Services S.L. - # Jordi Ballester Alomar -# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from . import sale_stock +# © 2015-17 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from . import sale_order +from . import stock_move +from . import stock_warehouse diff --git a/sale_stock_operating_unit/models/sale_stock.py b/sale_stock_operating_unit/models/sale_order.py similarity index 66% rename from sale_stock_operating_unit/models/sale_stock.py rename to sale_stock_operating_unit/models/sale_order.py index 9260b5bb19..1577750539 100644 --- a/sale_stock_operating_unit/models/sale_stock.py +++ b/sale_stock_operating_unit/models/sale_order.py @@ -1,28 +1,10 @@ # -*- coding: utf-8 -*- -# © 2015 Eficent Business and IT Consulting Services S.L. - +# © 2015-17 Eficent Business and IT Consulting Services S.L. - # Jordi Ballester Alomar -# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# © 2015-17 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -from openerp import api, models, _ -from openerp.exceptions import ValidationError - - -class StockMove(models.Model): - _inherit = 'stock.move' - - @api.model - def _prepare_picking_assign(self, move): - """ - Override to add Operating Units to Picking. - """ - values = super(StockMove, self)._prepare_picking_assign(move) - sale_line = move.procurement_id and move.procurement_id.sale_line_id - if sale_line: - values.update({ - 'operating_unit_id': sale_line.order_id and - sale_line.order_id.operating_unit_id.id - }) - return values +from odoo import api, models, _ +from odoo.exceptions import ValidationError class SaleOrder(models.Model): @@ -46,9 +28,6 @@ def onchange_operating_unit_id(self): self.operating_unit_id.id)]) if warehouses: self.warehouse_id = warehouses[0] - if self.team_id and self.team_id.operating_unit_id != \ - self.operating_unit_id: - self.team_id = False @api.onchange('warehouse_id') def onchange_warehouse_id(self): diff --git a/sale_stock_operating_unit/models/stock_move.py b/sale_stock_operating_unit/models/stock_move.py new file mode 100644 index 0000000000..18107f0dbc --- /dev/null +++ b/sale_stock_operating_unit/models/stock_move.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# © 2015-17 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015-17 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from odoo import models + + +class StockMove(models.Model): + _inherit = 'stock.move' + + def _get_new_picking_values(self): + """ + Override to add Operating Units to Picking. + """ + values = super(StockMove, self)._prepare_picking_assign() + sale_line = self.procurement_id and self.procurement_id.sale_line_id + if sale_line: + values.update({ + 'operating_unit_id': sale_line.order_id and + sale_line.order_id.operating_unit_id.id + }) + return values diff --git a/sale_stock_operating_unit/models/stock_warehouse.py b/sale_stock_operating_unit/models/stock_warehouse.py new file mode 100644 index 0000000000..c4eabcc795 --- /dev/null +++ b/sale_stock_operating_unit/models/stock_warehouse.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# © 2015-17 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015-17 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from odoo import api, models, _ +from odoo.exceptions import ValidationError + + +class StockWarehouse(models.Model): + _inherit = 'stock.warehouse' + + @api.multi + @api.constrains('operating_unit_id') + def _check_existing_so_in_wh(self): + for rec in self: + sales = self.env['sales.order'].search([ + ('warehouse_id', '=', rec.id), + ('operating_unit_id', '!=', rec.operating_unit_id)]) + if sales: + raise ValidationError(_( + 'Sales Order records already exist(s) for this warehouse' + ' and operating unit.')) diff --git a/sale_stock_operating_unit/tests/__init__.py b/sale_stock_operating_unit/tests/__init__.py index a585db84eb..3dc1091e8f 100644 --- a/sale_stock_operating_unit/tests/__init__.py +++ b/sale_stock_operating_unit/tests/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# © 2015 Eficent Business and IT Consulting Services S.L. - +# © 2015-17 Eficent Business and IT Consulting Services S.L. - # Jordi Ballester Alomar -# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# © 2015-17 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import test_sale_stock_operating_unit diff --git a/sale_stock_operating_unit/tests/test_sale_stock_operating_unit.py b/sale_stock_operating_unit/tests/test_sale_stock_operating_unit.py index 90288d2416..a519e0c1fd 100644 --- a/sale_stock_operating_unit/tests/test_sale_stock_operating_unit.py +++ b/sale_stock_operating_unit/tests/test_sale_stock_operating_unit.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- -# © 2015 Eficent Business and IT Consulting Services S.L. - +# © 2015-17 Eficent Business and IT Consulting Services S.L. - # Jordi Ballester Alomar -# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# © 2015-17 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -from openerp.addons.sale_operating_unit.tests import test_sale_operating_unit +from odoo.addons.sale_operating_unit.tests import test_sale_operating_unit class TestSaleStockOperatingUnit(test_sale_operating_unit.