-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] temp model test access rule & fix OCA remarks
- Loading branch information
1 parent
c735f7f
commit f886227
Showing
7 changed files
with
128 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<data> | ||
<function | ||
model="base.exception" | ||
name="_import_acl_for_tmp_test_model"/> | ||
</data> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,77 @@ | ||
# Copyright 2017 Akretion (http://www.akretion.com) | ||
# Mourad EL HADJ MIMOUNE <[email protected]> | ||
import os | ||
from odoo import api, fields, models, tools | ||
import logging | ||
|
||
from odoo import fields, models, api | ||
_logger = logging.getLogger(__name__) | ||
|
||
testing = tools.config.get('test_enable') or os.environ.get('ODOO_TEST_ENABLE') | ||
if testing: | ||
class PurchaseTest(models.Model): | ||
_inherit = 'base.exception' | ||
_name = "base.exception.test.purchase" | ||
_description = "Base Ecxeption Test Model" | ||
|
||
class PurchaseTest(models.Model): | ||
_inherit = 'base.exception' | ||
_name = "base.exception.test.purchase" | ||
_description = "Base Ecxeption Test Model" | ||
rule_group = fields.Selection( | ||
selection_add=[('test_base', 'test')], | ||
default='test_base', | ||
) | ||
name = fields.Char(required=True) | ||
user_id = fields.Many2one('res.users', string='Responsible') | ||
state = fields.Selection( | ||
[('draft', 'New'), ('cancel', 'Cancelled'), | ||
('purchase', 'Purchase'), | ||
('to approve', 'To approve'), ('done', 'Done')], | ||
string="Status", readonly=True, default='draft') | ||
active = fields.Boolean(default=True) | ||
partner_id = fields.Many2one('res.partner', string='Partner') | ||
line_ids = fields.One2many( | ||
'base.exception.test.purchase.line', 'lead_id') | ||
amount_total = fields.Float( | ||
compute='_compute_amount_total', store=True) | ||
|
||
rule_group = fields.Selection( | ||
selection_add=[('test_base', 'test')], | ||
default='test_base', | ||
) | ||
name = fields.Char(required=True) | ||
user_id = fields.Many2one('res.users', string='Responsible') | ||
state = fields.Selection( | ||
[('draft', 'New'), ('cancel', 'Cancelled'), | ||
('purchase', 'Purchase'), | ||
('to approve', 'To approve'), ('done', 'Done')], | ||
string="Status", readonly=True, default='draft') | ||
active = fields.Boolean(default=True) | ||
partner_id = fields.Many2one('res.partner', string='Partner') | ||
line_ids = fields.One2many('base.exception.test.model.line', 'lead_id') | ||
amount_total = fields.Float(compute='_compute_amount_total', store=True) | ||
@api.depends('line_ids') | ||
def _compute_amount_total(self): | ||
for record in self: | ||
for line in record.line_ids: | ||
record.amount_total += line.amount * line.qty | ||
|
||
@api.depends('line_ids') | ||
def _compute_amount_total(self): | ||
for record in self: | ||
for line in record.line_ids: | ||
record.amount_total += line.amount * line.qty | ||
@api.constrains('ignore_exception', 'line_ids', 'state') | ||
def test_purchase_check_exception(self): | ||
orders = self.filtered(lambda s: s.state == 'purchase') | ||
if orders: | ||
orders._check_exception() | ||
|
||
@api.constrains('ignore_exception', 'line_ids', 'state') | ||
def test_purchase_check_exception(self): | ||
orders = self.filtered(lambda s: s.state == 'purchase') | ||
if orders: | ||
orders._check_exception() | ||
@api.multi | ||
def button_approve(self, force=False): | ||
self.write({'state': 'to approve'}) | ||
return {} | ||
|
||
@api.multi | ||
def button_approve(self, force=False): | ||
self.write({'state': 'to approve'}) | ||
return {} | ||
@api.multi | ||
def button_draft(self): | ||
self.write({'state': 'draft'}) | ||
return {} | ||
|
||
@api.multi | ||
def button_draft(self): | ||
self.write({'state': 'draft'}) | ||
return {} | ||
@api.multi | ||
def button_confirm(self): | ||
self.write({'state': 'purchase'}) | ||
return True | ||
|
||
@api.multi | ||
def button_confirm(self): | ||
self.write({'state': 'purchase'}) | ||
return True | ||
@api.multi | ||
def button_cancel(self): | ||
self.write({'state': 'cancel'}) | ||
|
||
@api.multi | ||
def button_cancel(self): | ||
self.write({'state': 'cancel'}) | ||
def test_base_get_lines(self): | ||
self.ensure_one() | ||
return self.line_ids | ||
|
||
def test_base_get_lines(self): | ||
self.ensure_one() | ||
return self.line_ids | ||
class LineTest(models.Model): | ||
_name = "base.exception.test.purchase.line" | ||
_description = "Base Ecxeption Test Model Line" | ||
|
||
|
||
class LineTest(models.Model): | ||
_name = "base.exception.test.model.line" | ||
_description = "Base Ecxeption Test Model Line" | ||
|
||
name = fields.Char() | ||
lead_id = fields.Many2one('base.exception.test.model', ondelete='cascade') | ||
qty = fields.Float() | ||
amount = fields.Float() | ||
name = fields.Char() | ||
lead_id = fields.Many2one('base.exception.test.purchase', | ||
ondelete='cascade') | ||
qty = fields.Float() | ||
amount = fields.Float() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,8 @@ | |
# Mourad EL HADJ MIMOUNE <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import api, fields, models | ||
from odoo import api, fields, models, _ | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class ExceptionRuleConfirm(models.AbstractModel): | ||
|
@@ -19,13 +20,15 @@ class ExceptionRuleConfirm(models.AbstractModel): | |
@api.model | ||
def default_get(self, field_list): | ||
res = super(ExceptionRuleConfirm, self).default_get(field_list) | ||
current_model = self._context.get('active_model') | ||
current_model = self.env.context.get('active_model') | ||
model_except_obj = self.env[current_model] | ||
active_ids = self._context.get('active_ids') | ||
assert len(active_ids) == 1, "Only 1 ID accepted, got %r" % active_ids | ||
active_ids = self.env.context.get('active_ids') | ||
if len(active_ids) > 1: | ||
raise ValidationError( | ||
_('Only 1 ID accepted, got %r.') % active_ids) | ||
active_id = active_ids[0] | ||
related_model_except = model_except_obj.browse(active_id) | ||
exception_ids = [e.id for e in related_model_except.exception_ids] | ||
exception_ids = related_model_except.exception_ids.ids | ||
res.update({'exception_ids': [(6, 0, exception_ids)]}) | ||
res.update({'related_model_id': active_id}) | ||
return res | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters