|
| 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) |
0 commit comments