Skip to content

Commit

Permalink
[MIG] sale_stock_operating_unit to v10.
Browse files Browse the repository at this point in the history
  • Loading branch information
LoisRForgeFlow authored and alan196 committed Feb 15, 2020
1 parent 88f2579 commit 2fe84a4
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 49 deletions.
16 changes: 7 additions & 9 deletions sale_stock_operating_unit/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=============
Expand All @@ -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
===========
Expand Down
4 changes: 2 additions & 2 deletions sale_stock_operating_unit/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 6 additions & 4 deletions sale_stock_operating_unit/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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):
Expand Down
23 changes: 23 additions & 0 deletions sale_stock_operating_unit/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions sale_stock_operating_unit/models/stock_warehouse.py
Original file line number Diff line number Diff line change
@@ -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.'))
4 changes: 2 additions & 2 deletions sale_stock_operating_unit/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit 2fe84a4

Please sign in to comment.