Skip to content

Commit

Permalink
Migrate to v9
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronHForgeFlow authored and alan196 committed Feb 15, 2020
1 parent 6fa62e0 commit 88f2579
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 31 deletions.
21 changes: 7 additions & 14 deletions sale_stock_operating_unit/README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.. image:: https://img.shields.io/badge/license-AGPLv3-blue.svg
:target: https://www.gnu.org/licenses/agpl.html
:alt: License: AGPL-3
.. image:: https://img.shields.io/badge/license-LGPLv3-blue.svg
:target: https://www.gnu.org/licenses/lgpl.html
:alt: License: LGPL-3

===============================
Operating Unit in Sales
Expand All @@ -11,10 +11,6 @@ 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.

Installation
============

No additional installation instructions are required.

Configuration
=============
Expand All @@ -33,13 +29,10 @@ Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/sale_stock_operating_unit/issues>`_. In case of trouble, please
<https://github.com/OCA/operating-unit/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
<https://github.com/OCA/
sale_stock_operating_unit/issues/new?body=module:%20
sale_stock_operating_unit%0Aversion:%20
7.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
help us smashing it by providing a detailed and welcomed feedback.


Credits
=======
Expand Down Expand Up @@ -68,4 +61,4 @@ 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.
To contribute to this module, please visit http://odoo-community.org.
2 changes: 1 addition & 1 deletion sale_stock_operating_unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# © 2015 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).
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from . import models
13 changes: 3 additions & 10 deletions sale_stock_operating_unit/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,22 @@
# © 2015 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).
# 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": "8.0.1.0.0",
"version": "9.0.1.0.0",
"author": "Eficent, Serpent Consulting Services Pvt. Ltd., "
"Odoo Community Association (OCA)",
"license": "LGPL-3",
"website": "http://www.eficent.com",
"category": "Sales Management",
"depends": [
"sale_stock",
"sale_operating_unit",
"stock_operating_unit",
],
"description": """
Operating Unit in Sales Stock
=============================
This module prevents a user from selecting a Warehouse in the Sale Shop
that does not belong to the same operating unit.
""",
"data": [],
'installable': True,
'active': False,
}
49 changes: 47 additions & 2 deletions sale_stock_operating_unit/models/sale_stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# © 2015 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 openerp import api, models
# 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):
Expand All @@ -22,3 +23,47 @@ def _prepare_picking_assign(self, move):
sale_line.order_id.operating_unit_id.id
})
return values


class SaleOrder(models.Model):
_inherit = 'sale.order'

@api.onchange('team_id')
def onchange_team_id(self):
super(SaleOrder, self).onchange_team_id()
if self.team_id and self.team_id.operating_unit_id:
warehouses = self.env['stock.warehouse'].search(
[('operating_unit_id', '=',
self.team_id.operating_unit_id.id)])
if warehouses:
self.warehouse_id = warehouses[0]

@api.onchange('operating_unit_id')
def onchange_operating_unit_id(self):
if self.operating_unit_id:
warehouses = self.env['stock.warehouse'].search(
[('operating_unit_id', '=',
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):
if self.warehouse_id:
self.operating_unit_id = self.warehouse_id.operating_unit_id
if self.team_id and self.team_id.operating_unit_id != \
self.operating_unit_id:
self.team_id = False

@api.multi
@api.constrains('operating_unit_id', 'warehouse_id')
def _check_wh_operating_unit(self):
for rec in self:
if rec.operating_unit_id and rec.operating_unit_id != \
rec.warehouse_id.operating_unit_id:
raise ValidationError(_('Configuration error!\nThe Operating'
'Unit in the Sales Order and in the'
' Warehouse must be the same.'))
2 changes: 1 addition & 1 deletion sale_stock_operating_unit/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# © 2015 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).
# 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
Expand Up @@ -2,8 +2,8 @@
# © 2015 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 openerp import netsvc
# 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


Expand All @@ -14,7 +14,7 @@ def setUp(self):
super(TestSaleStockOperatingUnit, self).setUp()

def _confirm_sale(self, sale):
sale.action_button_confirm()
sale.action_confirm()
return True

def test_security(self):
Expand Down

0 comments on commit 88f2579

Please sign in to comment.