Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] [9.0-mrp_operating_unit] flake8 #73

Open
wants to merge 21 commits into
base: 9.0-mrp_operating_unit
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ addon | version | summary
[account_operating_unit](account_operating_unit/) | 9.0.1.0.0 | Introduces Operating Unit fields in invoices and Accounting Entries with clearing account
[account_voucher_operating_unit](account_voucher_operating_unit/) | 9.0.1.0.0 | Introduces the operating unit to vouchers
[analytic_operating_unit](analytic_operating_unit/) | 9.0.1.0.0 | Analytic Operating Unit
[crm_claim_operating_unit](crm_claim_operating_unit/) | 9.0.1.0.0 | Operating Unit in CRM Claims
[crm_operating_unit](crm_operating_unit/) | 9.0.1.0.0 | Operating Unit in CRM
[hr_contract_operating_unit](hr_contract_operating_unit/) | 9.0.1.0.0 | HR Contract Operating Unit
[operating_unit](operating_unit/) | 9.0.1.0.0 | An operating unit (OU) is an organizational entity part of a company
[procurement_operating_unit](procurement_operating_unit/) | 9.0.1.0.0 | An operating unit (OU) is an organizational entity part of a company
[purchase_operating_unit](purchase_operating_unit/) | 9.0.1.0.0 | An operating unit (OU) is an organizational entity part of a company
[purchase_request_operating_unit](purchase_request_operating_unit/) | 9.0.1.0.0 | Operating Unit in Purchase Requests
[purchase_request_procurement_operating_unit](purchase_request_procurement_operating_unit/) | 9.0.1.0.0 | Purchase Request Procurement with Operating Units
[purchase_request_to_requisition_operating_unit](purchase_request_to_requisition_operating_unit/) | 9.0.1.0.0 | Purchase Request to Call for Bids with Operating Units
[purchase_request_to_rfq_operating_unit](purchase_request_to_rfq_operating_unit/) | 9.0.1.0.0 | Purchase Request to RFQ with Operating Units
[purchase_requisition_operating_unit](purchase_requisition_operating_unit/) | 9.0.1.0.0 | Operating Unit in Purchase Requisitions
[sale_operating_unit](sale_operating_unit/) | 9.0.1.0.0 | An operating unit (OU) is an organizational entity part of a company
[sale_stock_operating_unit](sale_stock_operating_unit/) | 9.0.1.0.0 | An operating unit (OU) is an organizational entity part of a company
[sales_team_operating_unit](sales_team_operating_unit/) | 9.0.1.0.0 | Sales Team Operating Unit
Expand Down
58 changes: 58 additions & 0 deletions crm_claim_operating_unit/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
.. image:: https://img.shields.io/badge/license-LGPLv3-blue.svg
:target: https://www.gnu.org/licenses/lgpl.html
:alt: License: LGPL-3

==============================
CRM Claim with Operating Units
==============================

This module introduces the following features:

* Adds the Operating Unit (OU) to the CRM Claim.

* User can only view and manage the claims associated to the warehouse of the Operating Units that he has access to.


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/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 Business and IT Consulting Services S.L. <[email protected]>
* Serpent Consulting Services Pvt. Ltd. <[email protected]>

Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://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 https://odoo-community.org.
7 changes: 7 additions & 0 deletions crm_claim_operating_unit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
# © 2015 Eficent Business and IT Consulting Services S.L.
# © 2015 Serpent Consulting Services Pvt. Ltd.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from . import models
from . import tests
21 changes: 21 additions & 0 deletions crm_claim_operating_unit/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# © 2015-17 Eficent Business and IT Consulting Services S.L.
# © 2015 Serpent Consulting Services Pvt. Ltd.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

{
"name": "Operating Unit in CRM Claims",
"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",
"depends": ["crm_claim", "operating_unit", "sales_team_operating_unit"],
"data": [
"security/crm_security.xml",
"views/crm_claim_view.xml"
],
'installable': True,
}
7 changes: 7 additions & 0 deletions crm_claim_operating_unit/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
# © 2015-17 Eficent Business and IT Consulting Services S.L.
# © 2015 Serpent Consulting Services Pvt. Ltd.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from . import crm_claim
from . import crm_team
80 changes: 80 additions & 0 deletions crm_claim_operating_unit/models/crm_claim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# -*- coding: utf-8 -*-
# © 2015-17 Eficent Business and IT Consulting Services S.L.
# © 2015 Serpent Consulting Services Pvt. Ltd.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from openerp import api, fields, models, _
from openerp.exceptions import ValidationError


class CRMClaim(models.Model):

_inherit = "crm.claim"

@api.model
def _default_operating_unit(self):
team_id = self.env['crm.team']._get_default_team_id()
team = self.env['crm.team'].sudo().browse(team_id)
if team.operating_unit_id:
for ou in self.env.user.operating_unit_ids:
if ou.id == team.operating_unit_id.id:
return team.operating_unit_id
return self.env.user.default_operating_unit_id
else:
return self.env.user.default_operating_unit_id

operating_unit_id = fields.Many2one(
comodel_name='operating.unit',
string='Operating Unit',
default=_default_operating_unit,
)

@api.onchange('team_id')
def onchange_team_id(self):
if self.team_id:
team = self.env['crm.team'].search([
('id', '=', self.team_id.id),
('operating_unit_id', 'in',
[g.id for g in self.env.user.operating_unit_ids])])
if team:
self.operating_unit_id = team.operating_unit_id
else:
self.team_id = False
self.operating_unit_id = False

@api.onchange('operating_unit_id')
def onchange_operating_unit_id(self):
if self.operating_unit_id:
if self.operating_unit_id.id in \
[g.id for g in self.env.user.operating_unit_ids]:
if ((not self.team_id) or
(self.team_id and self.team_id.operating_unit_id !=
self.operating_unit_id)):
team = self.env['crm.team'].search(
[('operating_unit_id', 'in',
[self.operating_unit_id.id])], limit=1)
if team:
self.team_id = team
else:
self.team_id = False
else:
self.team_id = False
self.operating_unit_id = False

@api.multi
@api.constrains('team_id')
def _check_team_operating_unit(self):
for rec in self:
if rec.operating_unit_id:
if rec.team_id and rec.team_id.operating_unit_id != \
rec.operating_unit_id:
raise ValidationError(_('Configuration error\n'
'The Operating Unit of the claim '
'must match with that of the '
'sales team.'))
else:
raise ValidationError(_('Configuration error\n'
'The claim should be assigned to a '
'sales team and the Operating Unit '
'of the claim must match with that '
'of the sales team.'))
23 changes: 23 additions & 0 deletions crm_claim_operating_unit/models/crm_team.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.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from openerp import api, models, _
from openerp.exceptions import ValidationError


class CRMTeam(models.Model):

_inherit = "crm.team"

@api.multi
@api.constrains('operating_unit_id')
def _check_team_operating_unit(self):
for rec in self:
claim = self.env['crm.claim'].search(
[('team_id', '=', rec.id), ('operating_unit_id', '!=',
rec.operating_unit_id.id)])
if claim:
raise ValidationError(_('Configuration error\n'
'Claims already exists with another '
'Operation Unit'))
21 changes: 21 additions & 0 deletions crm_claim_operating_unit/security/crm_security.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2015 Eficent Business and IT Consulting Services S.L.
Serpent Consulting Services Pvt. Ltd.
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) -->
<odoo>
<data noupdate="0">

<record id="ir_rule_crm_claim_allowed_operating_units"
model="ir.rule">
<field name="model_id" ref="crm_claim.model_crm_claim"/>
<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">Claims 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>
</odoo>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions crm_claim_operating_unit/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# © 2015 Eficent Business and IT Consulting Services S.L. -
# Jordi Ballester Alomar
# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from . import test_crm_claim_operating_unit
106 changes: 106 additions & 0 deletions crm_claim_operating_unit/tests/test_crm_claim_operating_unit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# -*- coding: utf-8 -*-
# © 2015-17 Eficent Business and IT Consulting Services S.L.
# © 2015 Serpent Consulting Services Pvt. Ltd..
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from openerp.tests import common


class TestCrmClaimOperatingUnit(common.TransactionCase):

def setUp(self):
super(TestCrmClaimOperatingUnit, self).setUp()
self.res_users_model = self.env['res.users']
self.crm_claim_model = self.env['crm.claim']
self.crm_team_model = self.env['crm.team']

self.company = self.env.ref('base.main_company')
self.partner = self.env.ref('base.res_partner_1')
self.grp_sale_manager = self.env.ref('base.group_sale_manager')

# Main Operating Unit
self.main_OU = self.env.ref('operating_unit.main_operating_unit')
# B2C Operating Unit
self.b2c_OU = self.env.ref('operating_unit.b2c_operating_unit')

# Users
self.user1 = self._create_user('user_1',
[self.grp_sale_manager],
self.company,
[self.main_OU, self.b2c_OU])
self.user2 = self._create_user('user_2',
[self.grp_sale_manager],
self.company,
[self.b2c_OU])
self.user3 = self._create_user('user_3',
[self.grp_sale_manager],
self.company,
[self.main_OU, self.b2c_OU])
# Teams
self.team1 = self._create_crm_team(self.user1.id, self.main_OU)
self.team2 = self._create_crm_team(self.user2.id, self.b2c_OU)

# Claims
self.crm_claim1 = self._create_crm_claim(self.user1.id, self.main_OU)
self.crm_claim2 = self._create_crm_claim(self.user2.id, self.b2c_OU)
self.crm_claim3 = self._create_crm_claim(self.user3.id)

def _create_user(self, login, groups, company, operating_units):
"""Creates a user."""
group_ids = [group.id for group in groups]
user = self.res_users_model.create({
'name': login,
'login': login,
'password': 'demo',
'email': '[email protected]',
'company_id': company.id,
'company_ids': [(4, company.id)],
'operating_unit_ids': [(4, ou.id) for ou in operating_units],
'groups_id': [(6, 0, group_ids)]
})
return user

def _create_crm_team(self, uid, operating_unit):
"""Create a CRM team."""
context = {'mail_create_nosubscribe': True}
crm = self.crm_team_model.create({
'name': 'CRM team (' + operating_unit.name + ')',
'operating_unit_id': operating_unit.id
}, context=context)
return crm

def _create_crm_claim(self, uid, operating_unit=False):
"""Creates a CRM Claim."""
if not operating_unit:
operating_unit = self.crm_claim_model.sudo(uid).\
_default_operating_unit()
claim = self.crm_claim_model.sudo(uid).create({
'name': " Damaged Products ",
'operating_unit_id': operating_unit.id,
'partner_id': self.partner.id,
'user_id': uid,
'team_id': self.crm_team_model.search(
[('operating_unit_id', 'in', [operating_unit.id])],
limit=1).id
})
claim.onchange_team_id()
claim.onchange_operating_unit_id()
return claim

def test_security(self):
# User 2 is only assigned to Operating Unit B2C, and cannot
# access claims of Main Operating Unit.
record = self.crm_claim_model.sudo(
self.user2.id).search([('id', '=', self.crm_claim1.id),
('operating_unit_id', '=',
self.main_OU.id)])
self.assertEqual(record.ids, [], 'User 2 should not have access to '
'OU %s.' % self.main_OU.name)

def test_onchange(self):

self.crm_claim3.operating_unit_id = self.b2c_OU
self.crm_claim3.onchange_operating_unit_id()

self.assertEqual(self.crm_claim3.team_id.operating_unit_id,
self.b2c_OU, 'User 3 should have '
'assigned the operating unit %s.' % self.b2c_OU)
Loading