Skip to content

Commit 351885c

Browse files
committed
[MIG] base_exception: Migration to 11.0
1 parent bc3e184 commit 351885c

File tree

11 files changed

+291
-114
lines changed

11 files changed

+291
-114
lines changed

.travis.yml

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,15 @@ addons:
1212
packages:
1313
- expect-dev # provides unbuffer utility
1414
- python-lxml # because pip installation is slow
15-
- unixodbc-dev
16-
- python-mysqldb
1715

1816
env:
1917
global:
2018
- VERSION="11.0" TESTS="0" LINT_CHECK="0" TRANSIFEX="0"
21-
- TRANSIFEX_USER='transbot@odoo-community.org'
22-
- secure: Z06mZCN+Hm3myqHSOZpOOk1pd4oq1epAWZv6m9OX2bTNHbhyOVOGK6JWWsnDm/3DUCN1ZeLtSGOl9bvQfMa8ahQHA80MkLL16YlTvQV59Lh+L2gAYmxX+ogJCJgeQSVAXlGLscgkADCu/HzDlmatrDeROMtULn5i23j2qcyUNyM=
2319

2420
matrix:
2521
- LINT_CHECK="1"
26-
- TRANSIFEX="1"
27-
- TESTS="1" ODOO_REPO="OCA/OCB" EXCLUDE="database_cleanup"
28-
- TESTS="1" ODOO_REPO="odoo/odoo" EXCLUDE="database_cleanup"
29-
- TESTS="1" ODOO_REPO="OCA/OCB" INCLUDE="database_cleanup"
30-
- TESTS="1" ODOO_REPO="odoo/odoo" INCLUDE="database_cleanup"
31-
22+
- TESTS="1" ODOO_REPO="OCA/OCB"
23+
- TESTS="1" ODOO_REPO="odoo/odoo"
3224

3325
before_install:
3426
- "export PATH=$PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64/bin:$PATH"
@@ -41,12 +33,9 @@ install:
4133
- git clone https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools
4234
- export PATH=${HOME}/maintainer-quality-tools/travis:${PATH}
4335
- travis_install_nightly
44-
# Install libraries that require specific development headers, but not during lint test
45-
- if ! [ "$LINT_CHECK" = "1" ]; then pip install pymssql MySQL-python pyodbc; fi
46-
- printf '[options]\n\nrunning_env = dev\n' > ${HOME}/.openerp_serverrc
47-
- ln -s ${TRAVIS_BUILD_DIR}/server_environment_files_sample ${TRAVIS_BUILD_DIR}/server_environment_files
36+
4837
script:
4938
- travis_run_tests
5039

5140
after_success:
52-
- travis_after_tests_success
41+
- travis_after_tests_success

base_exception/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
44

55
from . import wizard, models
6+
from .tests import test_tmp_model

base_exception/__manifest__.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
# -*- coding: utf-8 -*-
22
# © 2011 Raphaël Valyi, Renato Lima, Guewen Baconnier, Sodexis
3+
# © 2017 Akretion (http://www.akretion.com)
4+
# Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
35
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
46

5-
{'name': 'Exception Rule',
6-
'version': '10.0.1.0.0',
7-
'category': 'Generic Modules',
8-
'summary': """This module provide an abstract model to manage customizable
9-
exceptions to be applied on different models (sale order, invoice, ...)""",
10-
'author': "Akretion, Sodexis, Camptocamp, Odoo Community Association (OCA)",
11-
'website': 'http://www.akretion.com',
12-
'depends': ['base_setup'],
13-
'license': 'AGPL-3',
14-
'data': [
15-
'security/base_exception_security.xml',
16-
'security/ir.model.access.csv',
17-
'wizard/base_exception_confirm_view.xml',
18-
'views/base_exception_view.xml',
19-
],
20-
'installable': True,
21-
}
7+
{
8+
'name': 'Exception Rule',
9+
'version': '11.0.1.0.0',
10+
'category': 'Generic Modules',
11+
'summary': """
12+
This module provide an abstract model to manage customizable
13+
exceptions to be applied on different models (sale order, invoice, ...)""",
14+
'author':
15+
"Akretion, Sodexis, Camptocamp, Odoo Community Association (OCA)",
16+
'website': 'http://www.akretion.com',
17+
'depends': ['base_setup'],
18+
'license': 'AGPL-3',
19+
'data': [
20+
'security/base_exception_security.xml',
21+
'security/ir.model.access.csv',
22+
'wizard/base_exception_confirm_view.xml',
23+
'views/base_exception_view.xml',
24+
],
25+
'installable': True,
26+
}

base_exception/models/base_exception.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# -*- coding: utf-8 -*-
22
# © 2011 Raphaël Valyi, Renato Lima, Guewen Baconnier, Sodexis
3+
# © 2017 Akretion (http://www.akretion.com)
4+
# Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
35
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
46

57
import time
@@ -42,6 +44,7 @@ class ExceptionRule(models.Model):
4244
selection=[],
4345
string='Apply on', required=True)
4446
active = fields.Boolean('Active')
47+
next_state = fields.Char('Next state')
4548
code = fields.Text(
4649
'Python Code',
4750
help="Python code executed to check if the exception apply or "
@@ -63,6 +66,26 @@ class ExceptionRule(models.Model):
6366
# - context: current context
6467
""")
6568

69+
@api.constrains('next_state')
70+
def _check_next_state_value(self):
71+
""" Ensure that the next_state value is in the state values of
72+
destination model """
73+
for rule in self:
74+
if rule.next_state:
75+
select_vals = self.env[
76+
rule.model].fields_get()[
77+
'state']['selection']
78+
if rule.next_state\
79+
not in [s[0] for s in select_vals]:
80+
raise ValidationError(
81+
_('The value "%s" you chose for the "next state" '
82+
'field state of "%s" is wrong.'
83+
' Value must be in this list %s')
84+
% (rule.next_state,
85+
rule.model,
86+
select_vals)
87+
)
88+
6689

6790
class BaseException(models.AbstractModel):
6891
_name = 'base.exception'
@@ -182,7 +205,7 @@ def _rule_eval(self, rule, obj_name, rec):
182205
space,
183206
mode='exec',
184207
nocopy=True) # nocopy allows to return 'result'
185-
except Exception, e:
208+
except Exception as e:
186209
raise UserError(
187210
_('Error when evaluating the exception.rule '
188211
'rule:\n %s \n(%s)') % (rule.name, e))
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
2-
"access_exception_rule","base.exception","model_exception_rule","base.group_user",1,0,0,0
3-
"access_exception_rule_manager","base.exception","model_exception_rule","base_exception.group_exception_rule_manager",1,1,1,1
4-
"access_base_exception","base.exception","model_base_exception","base.group_user",1,0,0,0
5-
"access_base_exception_manager","base.exception","model_base_exception","base_exception.group_exception_rule_manager",1,1,1,1
1+
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
2+
access_exception_rule,base.exception,model_exception_rule,base.group_user,1,0,0,0
3+
access_exception_rule_manager,base.exception,model_exception_rule,base_exception.group_exception_rule_manager,1,1,1,1
4+
access_base_exception,base.exception,model_base_exception,base.group_user,1,0,0,0
5+
access_base_exception_manager,base.exception,model_base_exception,base_exception.group_exception_rule_manager,1,1,1,1
6+
access_base_exception_test_purchase,access_base_exception_test_purchase,model_base_exception_test_purchase,base.group_system,1,1,1,1
7+
access_base_exception_test_model_line,access_base_exception_test_model_line,model_base_exception_test_model_line,base.group_system,1,1,1,1

base_exception/tests/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from . import test_tmp_model
4+
from . import test_base_exception
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# -*- coding: utf-8 -*-
2+
# © 2016 Akretion Mourad EL HADJ MIMOUNE
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
4+
5+
from odoo.tests import common
6+
7+
import logging
8+
9+
_logger = logging.getLogger(__name__)
10+
11+
12+
# @common.at_install(False)
13+
# @common.post_install(True)
14+
class TestBaseException(common.TransactionCase):
15+
16+
def setUp(self):
17+
super(TestBaseException, self).setUp()
18+
19+
self.base_exception = self.env['base.exception']
20+
self.exception_rule = self.env['exception.rule']
21+
self.exception_confirm = self.env['exception.rule.confirm']
22+
23+
self.exception_rule._fields['rule_group'].selection.append(
24+
('test_base', 'test base exception')
25+
)
26+
self.exception_rule._fields['model'].selection.append(
27+
('base.exception.test.purchase',
28+
'base.exception.test.purchase')
29+
)
30+
self.exception_rule._fields['model'].selection.append(
31+
('base.exception.test.purchase.line',
32+
'base.exception.test.purchase.line')
33+
)
34+
self.exceptionnozip = self.env['exception.rule'].create({
35+
'name': "No ZIP code on destination",
36+
'sequence': 10,
37+
'rule_group': "test_base",
38+
'model': "base.exception.test.purchase",
39+
'code': """if not test_base.partner_id.zip:
40+
failed=True""",
41+
})
42+
self.exceptionno_minorder = self.env['exception.rule'].create({
43+
'name': "Min order except",
44+
'sequence': 10,
45+
'rule_group': "test_base",
46+
'model': "base.exception.test.purchase",
47+
'code': """if test_base.amount_total <= 200.0:
48+
failed=True""",
49+
})
50+
51+
self.exceptionno_lineqty = self.env['exception.rule'].create({
52+
'name': "Qty > 0",
53+
'sequence': 10,
54+
'rule_group': "test_base",
55+
'model': "base.exception.test.purchase.line",
56+
'code': """if test_base_line.qty <= 0:
57+
failed=True"""})
58+
59+
def test_sale_order_exception(self):
60+
partner = self.env.ref('base.res_partner_1')
61+
partner.zip = False
62+
potest1 = self.env['base.exception.test.purchase'].create({
63+
'name': 'Test base exception to basic purchase',
64+
'partner_id': partner.id,
65+
'line_ids': [(0, 0, {'name': "line test",
66+
'amount': 120.0,
67+
'qty': 1.5})],
68+
})
69+
70+
potest1.button_confirm()
71+
# Set ignore_exception flag (Done after ignore is selected at wizard)
72+
potest1.ignore_exception = True
73+
potest1.button_confirm()
74+
self.assertTrue(potest1.state == 'purchase')
75+
# Simulation the opening of the wizard exception_confirm and
76+
# set ignore_exception to True
77+
except_confirm = self.exception_confirm.with_context(
78+
{
79+
'active_id': potest1.id,
80+
'active_ids': [potest1.id],
81+
'active_model': potest1._name
82+
}).new({'ignore': True})
83+
except_confirm.action_confirm()
84+
self.assertTrue(potest1.ignore_exception)
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# -*- coding: utf-8 -*-
2+
# © 2017 Akretion (http://www.akretion.com)
3+
# Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
4+
5+
from odoo import fields, models, api
6+
7+
8+
class PurchaseTest(models.Model):
9+
_inherit = 'base.exception'
10+
_name = "base.exception.test.purchase"
11+
_description = "Base Ecxeption Test Model"
12+
13+
rule_group = fields.Selection(
14+
selection_add=[('test_base', 'test')],
15+
default='test_base',
16+
)
17+
name = fields.Char(required=True)
18+
user_id = fields.Many2one('res.users', string='Responsible')
19+
state = fields.Selection(
20+
[('draft', 'New'), ('cancel', 'Cancelled'),
21+
('purchase', 'Purchase'),
22+
('to approve', 'To approve'), ('done', 'Done')],
23+
string="Status", readonly=True, default='draft')
24+
active = fields.Boolean(default=True)
25+
partner_id = fields.Many2one('res.partner', string='Partner')
26+
line_ids = fields.One2many('base.exception.test.model.line', 'lead_id')
27+
amount_total = fields.Float(compute='_compute_amount_total', store=True)
28+
29+
@api.depends('line_ids')
30+
def _compute_amount_total(self):
31+
for record in self:
32+
for line in record.line_ids:
33+
record.amount_total += line.amount * line.qty
34+
35+
@api.constrains('ignore_exception', 'line_ids', 'state')
36+
def test_purchase_check_exception(self):
37+
orders = self.filtered(lambda s: s.state == 'purchase')
38+
if orders:
39+
orders._check_exception()
40+
41+
@api.multi
42+
def button_approve(self, force=False):
43+
self.write({'state': 'to approve'})
44+
return {}
45+
46+
@api.multi
47+
def button_draft(self):
48+
self.write({'state': 'draft'})
49+
return {}
50+
51+
@api.multi
52+
def button_confirm(self):
53+
self.write({'state': 'purchase'})
54+
return True
55+
56+
@api.multi
57+
def button_cancel(self):
58+
self.write({'state': 'cancel'})
59+
60+
def test_base_get_lines(self):
61+
self.ensure_one()
62+
return self.line_ids
63+
64+
65+
class LineTest(models.Model):
66+
_name = "base.exception.test.model.line"
67+
_description = "Base Ecxeption Test Model Line"
68+
69+
name = fields.Char()
70+
lead_id = fields.Many2one('base.exception.test.model', ondelete='cascade')
71+
qty = fields.Float()
72+
amount = fields.Float()

0 commit comments

Comments
 (0)