Skip to content

Commit

Permalink
Merge a8282df into dc2517a
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiBForgeFlow committed Sep 28, 2016
2 parents dc2517a + a8282df commit aa1333a
Show file tree
Hide file tree
Showing 14 changed files with 734 additions and 0 deletions.
70 changes: 70 additions & 0 deletions stock_operating_unit/README.rst
@@ -0,0 +1,70 @@
.. image:: https://img.shields.io/badge/license-AGPLv3-blue.svg
:target: https://www.gnu.org/licenses/lgpl.html
:alt: License: LGPL-3

==========================
Stock with Operating Units
==========================

This module introduces the following features:
- Adds the operating unit to the Warehouse.
- Adds the operating unit to the Stock Location.
- Adds the requesting operating unit to stock pickings.
- Implements user's security access rules.


Configuration
=============

To configure this module, you need to:

* Assign Operating Unit to Warehouses.
* Assign Operating Unit to Stock Locations.

Usage
=====

This module defines the operating unit entity and the user's security rules.
Other modules extend the standard Odoo apps with the OU.

.. 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/9.0

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

Bugs are tracked on `GitHub Issues
<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.


Credits
=======

Images
------

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

Contributors
------------

* Eficent <contact@eficent.com>
* Serpent Consulting Services Pvt. Ltd. <support@serpentcs.com>

Maintainer
----------

.. image:: https://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.
5 changes: 5 additions & 0 deletions stock_operating_unit/__init__.py
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 Eficent Business and IT Consulting Services S.L.
# © 2016 Serpent Consulting Services Pvt. Ltd.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from . import model
26 changes: 26 additions & 0 deletions stock_operating_unit/__openerp__.py
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# © 2016 Eficent Business and IT Consulting Services S.L.
# © 2016 Serpent Consulting Services Pvt. Ltd.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

{
"name": "Stock with Operating Units",
"summary": "An operating unit (OU) is an organizational entity part of a\
company",
"version": "9.0.1.0.0",
"category": "Generic Modules/Sales & Purchases",
"author": "Eficent, Serpent Consulting Services Pvt. Ltd., "
"Odoo Community Association (OCA)",
"license": "LGPL-3",
"website": "http://www.eficent.com",
"depends": ["stock", "account_operating_unit"],
"data": [
"security/stock_security.xml",
"data/stock_data.xml",
"view/stock.xml",
],
"demo": [
"demo/stock_demo.xml",
],
"installable": True,
}
14 changes: 14 additions & 0 deletions stock_operating_unit/data/stock_data.xml
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">

<record id="stock.warehouse0" model="stock.warehouse">
<field name="operating_unit_id" ref="operating_unit.main_operating_unit"/>
</record>

<record id="stock.stock_location_stock" model="stock.location">
<field name="operating_unit_id" ref="operating_unit.main_operating_unit"/>
</record>

</data>
</openerp>
57 changes: 57 additions & 0 deletions stock_operating_unit/demo/stock_demo.xml
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">

<!-- Shelf 2 stock location -->
<record id="stock.stock_location_14" model="stock.location">
<field name="operating_unit_id" ref="operating_unit.main_operating_unit"/>
</record>

<!-- Shelf 1 stock location -->
<record id="stock.stock_location_components" model="stock.location">
<field name="operating_unit_id" ref="operating_unit.main_operating_unit"/>
</record>

<!-- Multi Company -->
<!-- Child Company 1-->
<record id="stock.res_company_1" model="res.company">
<field name="name">Your company child</field>
</record>

<record id="operating_unit_shop0" model="operating.unit">
<field name="name">Chicago</field>
<field name="code">CH</field>
<field name="partner_id" ref="stock.res_partner_company_1"/>
<field name="company_id" ref="stock.res_company_1"/>
</record>

<!-- Chicago Warehouse -->
<record id="stock.stock_warehouse_shop0" model="stock.warehouse">
<field name="operating_unit_id" ref="stock_operating_unit.operating_unit_shop0"/>
</record>

<!-- Your Company, Chicago shop -->
<record id="stock.stock_location_shop0" model="stock.location">
<field name="operating_unit_id" ref="operating_unit_shop0"/>
</record>

<!--B2B-->
<record id="stock_warehouse_b2b" model="stock.warehouse">
<field name="name">B2B Warehouse</field>
<field name="code">B2B</field>
<field name="partner_id" ref="base.main_partner"/>
<field name="company_id" ref="base.main_company"/>
<field name="operating_unit_id" ref="operating_unit.b2b_operating_unit"/>
</record>

<!-- B2C -->
<record id="stock_warehouse_b2c" model="stock.warehouse">
<field name="name">B2C Warehouse</field>
<field name="code">B2C</field>
<field name="partner_id" ref="base.main_partner"/>
<field name="company_id" ref="base.main_company"/>
<field name="operating_unit_id" ref="operating_unit.b2c_operating_unit"/>
</record>

</data>
</openerp>
5 changes: 5 additions & 0 deletions stock_operating_unit/model/__init__.py
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 Eficent Business and IT Consulting Services S.L.
# © 2016 Serpent Consulting Services Pvt. Ltd.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from . import stock
146 changes: 146 additions & 0 deletions stock_operating_unit/model/stock.py
@@ -0,0 +1,146 @@
# -*- coding: utf-8 -*-
# © 2016 Eficent Business and IT Consulting Services S.L.
# © 2016 Serpent Consulting Services Pvt. Ltd.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from openerp.tools.translate import _
from openerp import api, fields, models
from openerp.exceptions import Warning as UserError


class StockWarehouse(models.Model):
_inherit = "stock.warehouse"

operating_unit_id = fields.Many2one('operating.unit',
'Operating Unit',
default=lambda self:
self.env['res.users'].
operating_unit_default_get(self._uid))

@api.multi
@api.constrains('operating_unit_id', 'company_id')
def _check_company_operating_unit(self):
for rec in self:
if rec.company_id and rec.operating_unit_id and rec.company_id \
!= rec.operating_unit_id.company_id:
raise UserError(_('Configuration error!\nThe Company in the\
Stock Warehouse and in the Operating Unit must be the same.'))


class StockLocation(models.Model):
_inherit = 'stock.location'

operating_unit_id = fields.Many2one('operating.unit',
'Operating Unit')

@api.multi
@api.constrains('operating_unit_id')
def _check_warehouse_operating_unit(self):
for rec in self:
warehouse_obj = self.env['stock.warehouse']
warehouse = warehouse_obj.search([('wh_input_stock_loc_id', 'in',
rec.ids)])
for w in warehouse:
if rec.operating_unit_id != w.operating_unit_id:
raise UserError(_('Configuration error!\nThis location is\
assigned to a warehouse that belongs to a\
different operating unit.'))
warehouse = warehouse_obj.search([('lot_stock_id', 'in', rec.ids)])
for w in warehouse:
if self.operating_unit_id != w.operating_unit_id:
raise UserError(_('Configuration error!\nThis location is\
assigned to a warehouse that belongs to a\
different operating unit.'))
warehouse = warehouse_obj.search([('wh_output_stock_loc_id', 'in',
rec.ids)])
for w in warehouse:
if rec.operating_unit_id != w.operating_unit_id:
raise UserError(_('Configuration error!\nThis location is\
assigned to a warehouse that belongs to a different\
operating unit.'))

@api.multi
@api.constrains('operating_unit_id')
def _check_required_operating_unit(self):
for rec in self:
if rec.usage == 'internal' and not rec.operating_unit_id:
raise UserError(_('Configuration error!\nThe operating unit\
should be assigned to internal locations and to non other.'))
if rec.usage != 'internal' and rec.operating_unit_id:
raise UserError(_('Configuration error!\nThe operating unit\
should be assigned to internal locations and to non other.'))

@api.multi
@api.constrains('operating_unit_id', 'company_id')
def _check_company_operating_unit(self):
for rec in self:
if rec.company_id and rec.operating_unit_id and\
rec.company_id != rec.operating_unit_id.company_id:
raise UserError(_('Configuration error!\nThe Company in the\
Stock Location and in the Operating Unit must be the same.'))

@api.multi
@api.constrains('operating_unit_id', 'location_id')
def _check_parent_operating_unit(self):
for rec in self:
if (
rec.location_id and
rec.location_id.usage == 'internal' and
rec.operating_unit_id and
rec.operating_unit_id != rec.location_id.operating_unit_id
):
raise UserError(_('Configuration error!\nThe Parent\
Stock Location must belong to the same Operating Unit.'))


class StockPicking(models.Model):
_inherit = 'stock.picking'

operating_unit_id = fields.Many2one('operating.unit',
'Requesting Operating Unit',
default=lambda self:
self.env['res.users'].
operating_unit_default_get(self._uid))

@api.multi
@api.constrains('operating_unit_id', 'company_id')
def _check_company_operating_unit(self):
for rec in self:
if rec.company_id and rec.operating_unit_id and \
rec.company_id != rec.operating_unit_id.company_id:
raise UserError(_('Configuration error!\nThe Company in the\
Stock Picking and in the Operating Unit must be the same.'))

@api.multi
@api.constrains('operating_unit_id', 'move_lines')
def _check_stock_move_operating_unit(self):
for rec in self:
if not rec.operating_unit_id:
return True
operating_unit = rec.operating_unit_id
for sm in rec.move_lines:
if (
sm.location_id and
sm.location_id.operating_unit_id and
operating_unit != sm.location_id.operating_unit_id
) and (
sm.location_dest_id and
sm.location_dest_id.operating_unit_id and
operating_unit !=
sm.location_dest_id.operating_unit_id
):
raise UserError(_('Configuration error!\nThe Stock moves\
must be related to a location (source or destination)\
that belongs to the requesting Operating Unit.'))


class StockMove(models.Model):
_inherit = 'stock.move'

operating_unit_id =\
fields.Many2one('operating.unit',
related='location_id.operating_unit_id',
string='Source Location Operating Unit', readonly=True)
operating_unit_dest_id =\
fields.Many2one('operating.unit',
related='location_dest_id.operating_unit_id',
string='Dest. Location Operating Unit', readonly=True)
63 changes: 63 additions & 0 deletions stock_operating_unit/security/stock_security.xml
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">

<record id="ir_rule_stock_warehouse_allowed_operating_units" model="ir.rule">
<field name="model_id" ref="stock.model_stock_warehouse"/>
<field name="domain_force">['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])]</field>
<field name="name">Warehouses from allowed operating units</field>
<field name="global" eval="True"/>
<field eval="0" name="perm_unlink"/>
<field eval="0" name="perm_write"/>
<field eval="1" name="perm_read"/>
<field eval="0" name="perm_create"/>
</record>

<record id="ir_rule_stock_picking_type_allowed_operating_units" model="ir.rule">
<field name="model_id" ref="stock.model_stock_picking_type"/>
<field name="domain_force">['|',('warehouse_id.operating_unit_id','=',False),('warehouse_id.operating_unit_id','in',[g.id for g in user.operating_unit_ids])]</field>
<field name="name">Stock Picking Type from allowed operating units</field>
<field name="global" eval="True"/>
<field eval="0" name="perm_unlink"/>
<field eval="0" name="perm_write"/>
<field eval="1" name="perm_read"/>
<field eval="0" name="perm_create"/>
</record>

<record id="ir_rule_stock_location_allowed_operating_units" model="ir.rule">
<field name="model_id" ref="stock.model_stock_location"/>
<field name="domain_force">['|', ('operating_unit_id','in',[g.id for g
in user.operating_unit_ids]), ('operating_unit_id','=', False)]</field>
<field name="name">Stock locations from allowed operating units</field>
<field name="global" eval="True"/>
<field eval="0" name="perm_unlink"/>
<field eval="0" name="perm_write"/>
<field eval="1" name="perm_read"/>
<field eval="0" name="perm_create"/>
</record>

<record id="ir_rule_stock_move_allowed_operating_units" model="ir.rule">
<field name="model_id" ref="stock.model_stock_move"/>
<field name="domain_force">['|',('location_id.operating_unit_id','=',False),('location_id.operating_unit_id','in',[g.id for g in user.operating_unit_ids]),
'|',('location_dest_id.operating_unit_id','=',False),('location_dest_id.operating_unit_id','in',[g.id for g in user.operating_unit_ids])]</field>
<field name="name">Stock moves from allowed operating units</field>
<field name="global" eval="True"/>
<field eval="0" name="perm_unlink"/>
<field eval="0" name="perm_write"/>
<field eval="1" name="perm_read"/>
<field eval="0" name="perm_create"/>
</record>

<record id="ir_rule_stock_picking_allowed_operating_units" model="ir.rule">
<field name="model_id" ref="stock.model_stock_picking"/>
<field name="domain_force">['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])]</field>
<field name="name">Stock pickings from allowed operating units</field>
<field name="global" eval="True"/>
<field eval="0" name="perm_unlink"/>
<field eval="0" name="perm_write"/>
<field eval="1" name="perm_read"/>
<field eval="0" name="perm_create"/>
</record>

</data>
</openerp>
Binary file added stock_operating_unit/static/description/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit aa1333a

Please sign in to comment.