Browse Source
Merge pull request #55 from Eficent/11.0-imp-base_tier_validation
Merge pull request #55 from Eficent/11.0-imp-base_tier_validation
[11.0][IMP] base_tier_validationpull/60/head
Jordi Ballester Alomar
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 1480 additions and 78 deletions
-
1base_tier_validation/README.rst
-
10base_tier_validation/__manifest__.py
-
16base_tier_validation/migrations/11.0.1.2.0/post-migrate.py
-
1base_tier_validation/models/__init__.py
-
38base_tier_validation/models/res_users.py
-
32base_tier_validation/models/tier_definition.py
-
13base_tier_validation/models/tier_review.py
-
34base_tier_validation/models/tier_validation.py
-
1base_tier_validation/readme/CONTRIBUTORS.rst
-
31base_tier_validation/static/description/index.html
-
58base_tier_validation/static/src/js/review_widget.js
-
135base_tier_validation/static/src/js/systray.js
-
4base_tier_validation/static/src/less/review.less
-
113base_tier_validation/static/src/less/systray.less
-
41base_tier_validation/static/src/xml/systray.xml
-
63base_tier_validation/static/src/xml/tier_review_template.xml
-
6base_tier_validation/tests/common.py
-
84base_tier_validation/tests/test_tier_validation.py
-
21base_tier_validation/tests/tier_validation_tester.py
-
13base_tier_validation/views/assets_backend.xml
-
31base_tier_validation/views/tier_definition_view.xml
-
4base_tier_validation/views/tier_review_view.xml
-
81base_tier_validation_formula/README.rst
-
1base_tier_validation_formula/__init__.py
-
20base_tier_validation_formula/__manifest__.py
-
3base_tier_validation_formula/models/__init__.py
-
37base_tier_validation_formula/models/tier_definition.py
-
47base_tier_validation_formula/models/tier_review.py
-
25base_tier_validation_formula/models/tier_validation.py
-
2base_tier_validation_formula/readme/CONTRIBUTORS.rst
-
2base_tier_validation_formula/readme/DESCRIPTION.rst
-
2base_tier_validation_formula/readme/USAGE.rst
-
BINbase_tier_validation_formula/static/description/icon.png
-
405base_tier_validation_formula/static/description/index.html
-
4base_tier_validation_formula/tests/__init__.py
-
19base_tier_validation_formula/tests/common.py
-
112base_tier_validation_formula/tests/test_tier_validation.py
-
23base_tier_validation_formula/tests/tier_validation_tester.py
-
25base_tier_validation_formula/views/tier_definition_view.xml
@ -0,0 +1,16 @@ |
|||||
|
# Copyright 2019 Creu Blanca |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
from openupgradelib.openupgrade import migrate |
||||
|
|
||||
|
|
||||
|
@migrate() |
||||
|
def migrate(env, version): |
||||
|
module_ids = env['ir.module.module'].search([ |
||||
|
('name', '=', 'base_tier_validation_formula'), |
||||
|
('state', '=', 'uninstalled') |
||||
|
]) |
||||
|
if module_ids: |
||||
|
module_ids.sudo().button_install() |
||||
|
cr = env.cr |
||||
|
cr.execute("UPDATE tier_definition SET definition_type = 'formula'") |
@ -0,0 +1,38 @@ |
|||||
|
# Copyright 2019 Eficent Business and IT Consulting Services S.L. |
||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from odoo import api, fields, models, modules |
||||
|
|
||||
|
|
||||
|
class Users(models.Model): |
||||
|
_inherit = 'res.users' |
||||
|
|
||||
|
review_ids = fields.Many2many( |
||||
|
string="Reviews", comodel_name="tier.review" |
||||
|
) |
||||
|
|
||||
|
@api.model |
||||
|
def review_user_count(self): |
||||
|
user_reviews = {} |
||||
|
to_review_docs = {} |
||||
|
for review in self.env.user.review_ids.filtered( |
||||
|
lambda r: r.status == 'pending'): |
||||
|
record = review.env[review.model].browse(review.res_id) |
||||
|
if not user_reviews.get(review['model']): |
||||
|
user_reviews[review.model] = { |
||||
|
'name': record._description, |
||||
|
'model': review.model, |
||||
|
'icon': modules.module.get_module_icon( |
||||
|
self.env[review.model]._original_module), |
||||
|
'pending_count': 0 |
||||
|
} |
||||
|
docs = to_review_docs.get(review.model) |
||||
|
if (docs and record not in docs) or not docs: |
||||
|
user_reviews[review.model]['pending_count'] += 1 |
||||
|
to_review_docs.setdefault(review.model, []).append(record) |
||||
|
return list(user_reviews.values()) |
||||
|
|
||||
|
@api.model |
||||
|
def get_reviews(self, data): |
||||
|
return self.env['tier.review'].search_read( |
||||
|
[('id', 'in', data.get('res_ids'))]) |
@ -1 +1,2 @@ |
|||||
* Lois Rilo <lois.rilo@eficent.com> |
* Lois Rilo <lois.rilo@eficent.com> |
||||
|
* Adrià Gil Sorribes <adria.gil@eficent.com> |
@ -0,0 +1,58 @@ |
|||||
|
odoo.define('base_tier_validation.ReviewField', function (require) { |
||||
|
"use strict"; |
||||
|
|
||||
|
var AbstractField = require('web.AbstractField'); |
||||
|
var core = require('web.core'); |
||||
|
var session = require('web.session'); |
||||
|
var field_registry = require('web.field_registry'); |
||||
|
var Widget = require('web.Widget'); |
||||
|
|
||||
|
var _t = core._t; |
||||
|
var QWeb = core.qweb; |
||||
|
|
||||
|
var ReviewField = AbstractField.extend({ |
||||
|
template: 'tier.review.ReviewPopUp', |
||||
|
events: { |
||||
|
'click .o_info_btn': '_onButtonClicked', |
||||
|
}, |
||||
|
start: function () { |
||||
|
var self = this; |
||||
|
console.log(self) |
||||
|
|
||||
|
}, |
||||
|
/** |
||||
|
* Make RPC and get current user's activity details |
||||
|
* @private |
||||
|
*/ |
||||
|
_getReviewData: function(res_ids){ |
||||
|
var self = this; |
||||
|
|
||||
|
return self._rpc({ |
||||
|
model: 'res.users', |
||||
|
method: 'get_reviews', |
||||
|
args: [res_ids], |
||||
|
}).then(function (data) { |
||||
|
self.reviews = data; |
||||
|
}); |
||||
|
}, |
||||
|
_renderDropdown: function () { |
||||
|
var self = this; |
||||
|
return this._getReviewData(self.value).then(function (){ |
||||
|
self.$('.o_review').html(QWeb.render("tier.review.ReviewDropDown", { |
||||
|
reviews : self.reviews |
||||
|
})); |
||||
|
}); |
||||
|
}, |
||||
|
_onButtonClicked: function (event) { |
||||
|
event.preventDefault(); |
||||
|
if (!this.$el.hasClass('open')) { |
||||
|
this._renderDropdown(); |
||||
|
} |
||||
|
}, |
||||
|
}); |
||||
|
|
||||
|
field_registry.add('review_popup', ReviewField); |
||||
|
|
||||
|
return ReviewField; |
||||
|
|
||||
|
}); |
@ -0,0 +1,135 @@ |
|||||
|
odoo.define('tier_validation.systray', function (require) { |
||||
|
"use strict"; |
||||
|
|
||||
|
var config = require('web.config'); |
||||
|
var core = require('web.core'); |
||||
|
var session = require('web.session'); |
||||
|
var SystrayMenu = require('web.SystrayMenu'); |
||||
|
var Widget = require('web.Widget'); |
||||
|
var bus = require('bus.bus').bus; |
||||
|
|
||||
|
var chat_manager = require('mail.chat_manager'); |
||||
|
|
||||
|
var QWeb = core.qweb; |
||||
|
|
||||
|
var ReviewMenu = Widget.extend({ |
||||
|
template:'tier.validation.ReviewMenu', |
||||
|
events: { |
||||
|
"click": "_onReviewMenuClick", |
||||
|
"click .o_mail_channel_preview": "_onReviewFilterClick", |
||||
|
}, |
||||
|
start: function () { |
||||
|
this.$reviews_preview = this.$('.o_mail_navbar_dropdown_channels'); |
||||
|
this._updateReviewPreview(); |
||||
|
var channel = 'base.tier.validation'; |
||||
|
bus.add_channel(channel); |
||||
|
bus.on('notification', this, this._updateReviewPreview); |
||||
|
return this._super(); |
||||
|
}, |
||||
|
|
||||
|
// Private
|
||||
|
|
||||
|
/** |
||||
|
* Make RPC and get current user's activity details |
||||
|
* @private |
||||
|
*/ |
||||
|
_getReviewData: function(){ |
||||
|
var self = this; |
||||
|
|
||||
|
return self._rpc({ |
||||
|
model: 'res.users', |
||||
|
method: 'review_user_count', |
||||
|
kwargs: { |
||||
|
context: session.user_context, |
||||
|
}, |
||||
|
}).then(function (data) { |
||||
|
self.reviews = data; |
||||
|
self.reviewCounter = _.reduce(data, function(total_count, p_data){ return total_count + p_data.pending_count; }, 0); |
||||
|
self.$('.o_notification_counter').text(self.reviewCounter); |
||||
|
self.$el.toggleClass('o_no_notification', !self.reviewCounter); |
||||
|
}); |
||||
|
}, |
||||
|
/** |
||||
|
* Check wether activity systray dropdown is open or not |
||||
|
* @private |
||||
|
* @returns {boolean} |
||||
|
*/ |
||||
|
_isOpen: function () { |
||||
|
return this.$el.hasClass('open'); |
||||
|
}, |
||||
|
/** |
||||
|
* Update(render) activity system tray view on activity updation. |
||||
|
* @private |
||||
|
*/ |
||||
|
_updateReviewPreview: function () { |
||||
|
var self = this; |
||||
|
self._getReviewData().then(function (){ |
||||
|
self.$reviews_preview.html(QWeb.render('tier.validation.ReviewMenuPreview', { |
||||
|
reviews : self.reviews |
||||
|
})); |
||||
|
}); |
||||
|
}, |
||||
|
/** |
||||
|
* update counter based on activity status(created or Done) |
||||
|
* @private |
||||
|
* @param {Object} [data] key, value to decide activity created or deleted |
||||
|
* @param {String} [data.type] notification type |
||||
|
* @param {Boolean} [data.activity_deleted] when activity deleted |
||||
|
* @param {Boolean} [data.activity_created] when activity created |
||||
|
*/ |
||||
|
_updateCounter: function (data) { |
||||
|
if (data) { |
||||
|
if (data.review_created) { |
||||
|
this.reviewCounter ++; |
||||
|
} |
||||
|
if (data.review_deleted && this.reviewCounter > 0) { |
||||
|
this.reviewCounter --; |
||||
|
} |
||||
|
this.$('.o_notification_counter').text(this.reviewCounter); |
||||
|
this.$el.toggleClass('o_no_notification', !this.reviewCounter); |
||||
|
} |
||||
|
}, |
||||
|
|
||||
|
|
||||
|
// Handlers
|
||||
|
|
||||
|
/** |
||||
|
* Redirect to particular model view |
||||
|
* @private |
||||
|
* @param {MouseEvent} event |
||||
|
*/ |
||||
|
_onReviewFilterClick: function (event) { |
||||
|
// fetch the data from the button otherwise fetch the ones from the parent (.o_tier_channel_preview).
|
||||
|
var data = _.extend({}, $(event.currentTarget).data(), $(event.target).data()); |
||||
|
var context = {}; |
||||
|
this.do_action({ |
||||
|
type: 'ir.actions.act_window', |
||||
|
name: data.model_name, |
||||
|
res_model: data.res_model, |
||||
|
views: [[false, 'list'], [false, 'form']], |
||||
|
search_view_id: [false], |
||||
|
domain: [['review_ids.reviewer_ids', '=', session.uid], |
||||
|
['review_ids.status', '=', 'pending']], |
||||
|
context:context, |
||||
|
}); |
||||
|
}, |
||||
|
/** |
||||
|
* When menu clicked update activity preview if counter updated |
||||
|
* @private |
||||
|
* @param {MouseEvent} event |
||||
|
*/ |
||||
|
_onReviewMenuClick: function () { |
||||
|
if (!this._isOpen()) { |
||||
|
this._updateReviewPreview(); |
||||
|
} |
||||
|
}, |
||||
|
|
||||
|
}); |
||||
|
|
||||
|
SystrayMenu.Items.push(ReviewMenu); |
||||
|
|
||||
|
// to test activity menu in qunit test cases we need it
|
||||
|
return { |
||||
|
ReviewMenu: ReviewMenu, |
||||
|
}; |
||||
|
}); |
@ -0,0 +1,4 @@ |
|||||
|
ul.o_review { |
||||
|
min-width: 600px; |
||||
|
max-width: 800px |
||||
|
} |
@ -0,0 +1,113 @@ |
|||||
|
// Navbar icon and dropdown |
||||
|
.o_tier_navbar_item { |
||||
|
> a { |
||||
|
opacity: 1; |
||||
|
> i { |
||||
|
font-size: larger; |
||||
|
} |
||||
|
} |
||||
|
&.o_no_notification > a { |
||||
|
opacity: 0.5; |
||||
|
> i { |
||||
|
.o-transform(translateY(0px)); |
||||
|
} |
||||
|
.o_notification_counter { |
||||
|
display: none; |
||||
|
} |
||||
|
} |
||||
|
&.open .o_tier_navbar_dropdown { |
||||
|
.o-flex-display(); |
||||
|
.o-flex-flow(column, nowrap); |
||||
|
} |
||||
|
.o_notification_counter { |
||||
|
.o-position-absolute(@top: 20%, @right: 1px); |
||||
|
background: @odoo-brand-optional; |
||||
|
color: white; |
||||
|
padding: 0em 0.3em; |
||||
|
font-size: 0.7em; |
||||
|
} |
||||
|
.o_tier_navbar_dropdown { |
||||
|
width: 350px; |
||||
|
padding: 0; |
||||
|
|
||||
|
.o_spinner { |
||||
|
.o-flex-display(); |
||||
|
.o-align-items(center); |
||||
|
.o-justify-content(center); |
||||
|
color: @odoo-main-text-color; |
||||
|
height: 50px; |
||||
|
} |
||||
|
|
||||
|
.o_tier_navbar_dropdown_channels { |
||||
|
.o-flex(0, 1, auto); |
||||
|
max-height: 400px; |
||||
|
min-height: 50px; |
||||
|
overflow-y: auto; |
||||
|
|
||||
|
@media (min-width: @screen-sm-min) { |
||||
|
.o_tier_channel_preview { |
||||
|
height: 50px; |
||||
|
padding: 5px; |
||||
|
.o_tier_channel_image { |
||||
|
width: 40px; |
||||
|
} |
||||
|
.o_channel_info { |
||||
|
margin-left: 10px; |
||||
|
.o_channel_title { |
||||
|
.o_last_message_date { |
||||
|
padding-top: 2px; |
||||
|
font-size: x-small; |
||||
|
margin-left: 10px; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
.o_no_review { |
||||
|
cursor: initial; |
||||
|
.o-align-items(center); |
||||
|
color: grey; |
||||
|
opacity: 0.5; |
||||
|
padding: 3px; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
.o_no_chat_window .o_tier_navbar_dropdown .o_new_message { |
||||
|
display: none; // hide 'new message' button if chat windows are disabled |
||||
|
} |
||||
|
|
||||
|
// Mobile rules |
||||
|
// Goal: mock the design of Discuss in mobile |
||||
|
@media (max-width: @screen-xs-max) { |
||||
|
.o_tier_navbar_item { |
||||
|
.o_notification_counter { |
||||
|
top: 10%; |
||||
|
} |
||||
|
.o_tier_navbar_dropdown { |
||||
|
position: relative; |
||||
|
.o_tier_navbar_dropdown_top { |
||||
|
padding: 5px; |
||||
|
} |
||||
|
.o_tier_navbar_mobile_header { |
||||
|
padding: 5px; |
||||
|
height: 44px; |
||||
|
border-bottom: 1px solid #ebebeb; |
||||
|
box-shadow: 0 0 2px @gray-lighter-darker; |
||||
|
} |
||||
|
.o_tier_navbar_dropdown_channels { |
||||
|
max-height: none; |
||||
|
padding-bottom: 52px; // leave space for tabs |
||||
|
} |
||||
|
.o_tier_mobile_tabs { |
||||
|
position: fixed; |
||||
|
bottom: 0px; |
||||
|
left: 0px; |
||||
|
right: 0px; |
||||
|
background-color: white; |
||||
|
color: @odoo-main-text-color; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,41 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<templates> |
||||
|
|
||||
|
<t t-name="tier.validation.ReviewMenuPreview"> |
||||
|
<t t-if="_.isEmpty(reviews)"> |
||||
|
<li class="text-center o_no_review"> |
||||
|
<span>No reviews to do.</span> |
||||
|
</li> |
||||
|
</t> |
||||
|
<t t-foreach="reviews" t-as="review"> |
||||
|
<div class="o_mail_channel_preview" t-att-data-res_model="review.model" t-att-data-model_name="review.name"> |
||||
|
<div class="o_mail_channel_image o_mail_channel_app"> |
||||
|
<img t-att-src="review.icon"/> |
||||
|
</div> |
||||
|
<div class="o_channel_info"> |
||||
|
<div class="o_channel_title"> |
||||
|
<span class="o_channel_name"> |
||||
|
<t t-esc="review.name"/> |
||||
|
</span> |
||||
|
</div> |
||||
|
<div> |
||||
|
<button t-if="review.pending_count" type="button" class="btn btn-link o_activity_filter_button mr16" t-att-data-res_model="review.model" t-att-data-model_name="review.name" data-filter='pending_count'><t t-esc="review.pending_count"/> Pending </button> |
||||
|
<span t-if="!review.pending_count" class="o_no_review mr16">0 Pending </span> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</t> |
||||
|
</t> |
||||
|
|
||||
|
<t t-name="tier.validation.ReviewMenu"> |
||||
|
<li class="o_mail_navbar_item"> |
||||
|
<a class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false" title="Reviews" href="#"> |
||||
|
<i class="fa fa-pencil-square-o"/> <span class="o_notification_counter badge"/> |
||||
|
</a> |
||||
|
<ul class="o_mail_navbar_dropdown dropdown-menu" role="menu"> |
||||
|
<li class="o_mail_navbar_dropdown_channels"/> |
||||
|
</ul> |
||||
|
</li> |
||||
|
</t> |
||||
|
|
||||
|
</templates> |
@ -0,0 +1,63 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<templates> |
||||
|
|
||||
|
<t t-name="tier.review.ReviewPopUp"> |
||||
|
<div class="dropdown btn btn-sm oe_stat_button"> |
||||
|
<div class="dropdown-toggle o_info_btn" data-toggle="dropdown" style="height:100%;width:100%;display:table"> |
||||
|
<div style="display:table-cell;vertical-align:middle"> |
||||
|
<div class="fa fa-fw o_button_icon fa-pencil-square-o"/> |
||||
|
<div class="o_field_widget o_stat_info o_readonly_modifier"> |
||||
|
<span class="o_stat_text">Reviews</span> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
<ul class="dropdown-menu o_review" role="menu" style="right:0;left: auto"> |
||||
|
</ul> |
||||
|
</div> |
||||
|
</t> |
||||
|
|
||||
|
<t t-name="tier.review.ReviewDropDown"> |
||||
|
<table class="oe_mt32 table table-condensed"> |
||||
|
<thead> |
||||
|
<tr> |
||||
|
<th class="text-center">Sequence</th> |
||||
|
<th class="text-left">Requested by</th> |
||||
|
<th class="text-right">Description</th> |
||||
|
<th class="text-right">Status</th> |
||||
|
<th class="text-right">Done by</th> |
||||
|
<th class="text-right">Validation Date</th> |
||||
|
</tr> |
||||
|
</thead> |
||||
|
<tbody class="sale_tbody"> |
||||
|
<t t-foreach="reviews" t-as="review"> |
||||
|
<t t-if="review.status == 'pending'" t-set="status_class" t-value=""/> |
||||
|
<t t-if="review.status == 'approved'" t-set="status_class" t-value="'alert-success'"/> |
||||
|
<t t-if="review.status == 'rejected'" t-set="status_class" t-value="'alert-danger'"/> |
||||
|
<tr t-att-class="status_class"> |
||||
|
<td class="text-center"> |
||||
|
<span t-esc="review.sequence"/> |
||||
|
</td> |
||||
|
<td class="text-left"> |
||||
|
<span t-esc="review.requested_by[1]"/> |
||||
|
</td> |
||||
|
<td class="text-right"> |
||||
|
<span t-esc="review.name"/> |
||||
|
</td> |
||||
|
<td class="text-right"> |
||||
|
<span t-esc="review.status"/> |
||||
|
</td> |
||||
|
<td class="text-right"> |
||||
|
<span t-esc="review.done_by[1]"/> |
||||
|
</td> |
||||
|
<td class="text-right"> |
||||
|
<t t-if="review.reviewed_date"> |
||||
|
<span t-esc="review.reviewed_date"/> |
||||
|
</t> |
||||
|
</td> |
||||
|
</tr> |
||||
|
</t> |
||||
|
</tbody> |
||||
|
</table> |
||||
|
</t> |
||||
|
|
||||
|
</templates> |
@ -0,0 +1,13 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<odoo> |
||||
|
<template id="assets_backend" name="mail assets" |
||||
|
inherit_id="web.assets_backend"> |
||||
|
<xpath expr="." position="inside"> |
||||
|
<script type="text/javascript" src="/base_tier_validation/static/src/js/systray.js"/> |
||||
|
<script type="text/javascript" src="/base_tier_validation/static/src/js/review_widget.js"/> |
||||
|
|
||||
|
<link rel="stylesheet" href="/base_tier_validation/static/src/less/systray.less" type="text/less"/> |
||||
|
<link rel="stylesheet" href="/base_tier_validation/static/src/less/review.less" type="text/less"/> |
||||
|
</xpath> |
||||
|
</template> |
||||
|
</odoo> |
@ -0,0 +1,81 @@ |
|||||
|
============================ |
||||
|
Base Tier Validation Formula |
||||
|
============================ |
||||
|
|
||||
|
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
||||
|
!! This file is generated by oca-gen-addon-readme !! |
||||
|
!! changes will be overwritten. !! |
||||
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
||||
|
|
||||
|
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png |
||||
|
:target: https://odoo-community.org/page/development-status |
||||
|
:alt: Beta |
||||
|
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png |
||||
|
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html |
||||
|
:alt: License: AGPL-3 |
||||
|
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--ux-lightgray.png?logo=github |
||||
|
:target: https://github.com/OCA/server-ux/tree/11.0/base_tier_validation_formula |
||||
|
:alt: OCA/server-ux |
||||
|
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png |
||||
|
:target: https://translation.odoo-community.org/projects/server-ux-11-0/server-ux-11-0-base_tier_validation_formula |
||||
|
:alt: Translate me on Weblate |
||||
|
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png |
||||
|
:target: https://runbot.odoo-community.org/runbot/250/11.0 |
||||
|
:alt: Try me on Runbot |
||||
|
|
||||
|
|badge1| |badge2| |badge3| |badge4| |badge5| |
||||
|
|
||||
|
This module includes the ability to define the tier definition domain |
||||
|
and the tier reviewers using python code. |
||||
|
|
||||
|
**Table of contents** |
||||
|
|
||||
|
.. contents:: |
||||
|
:local: |
||||
|
|
||||
|
Usage |
||||
|
===== |
||||
|
|
||||
|
To define the domain by python code choose the Formula option in the Definition field. |
||||
|
To define the reviewers by python code choose Python Expression option in the Validated by field. |
||||
|
|
||||
|
Bug Tracker |
||||
|
=========== |
||||
|
|
||||
|
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-ux/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 <https://github.com/OCA/server-ux/issues/new?body=module:%20base_tier_validation_formula%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. |
||||
|
|
||||
|
Do not contact contributors directly about support or help with technical issues. |
||||
|
|
||||
|
Credits |
||||
|
======= |
||||
|
|
||||
|
Authors |
||||
|
~~~~~~~ |
||||
|
|
||||
|
* Creu Blanca |
||||
|
|
||||
|
Contributors |
||||
|
~~~~~~~~~~~~ |
||||
|
|
||||
|
* Enric Tobella <etobella@creublanca.es> |
||||
|
* Adrià Gil Sorribes <adria.gil@eficent.com> |
||||
|
|
||||
|
Maintainers |
||||
|
~~~~~~~~~~~ |
||||
|
|
||||
|
This module is maintained by the OCA. |
||||
|
|
||||
|
.. image:: https://odoo-community.org/logo.png |
||||
|
:alt: Odoo Community Association |
||||
|
:target: https://odoo-community.org |
||||
|
|
||||
|
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. |
||||
|
|
||||
|
This module is part of the `OCA/server-ux <https://github.com/OCA/server-ux/tree/11.0/base_tier_validation_formula>`_ project on GitHub. |
||||
|
|
||||
|
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
@ -0,0 +1 @@ |
|||||
|
from . import models |
@ -0,0 +1,20 @@ |
|||||
|
# Copyright 2019 Creu Blanca |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
{ |
||||
|
'name': 'Base Tier Validation Formula', |
||||
|
'summary': """ |
||||
|
Formulas for Base tier validation""", |
||||
|
'version': '11.0.1.0.0', |
||||
|
'license': 'AGPL-3', |
||||
|
'author': 'Creu Blanca,Odoo Community Association (OCA)', |
||||
|
'website': 'www.creublanca.es', |
||||
|
'depends': [ |
||||
|
'base_tier_validation' |
||||
|
], |
||||
|
'data': [ |
||||
|
'views/tier_definition_view.xml', |
||||
|
], |
||||
|
'demo': [ |
||||
|
], |
||||
|
} |
@ -0,0 +1,3 @@ |
|||||
|
from . import tier_definition |
||||
|
from . import tier_validation |
||||
|
from . import tier_review |
@ -0,0 +1,37 @@ |
|||||
|
# Copyright 2019 Creu Blanca |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from odoo import fields, api, models |
||||
|
|
||||
|
|
||||
|
class TierDefinition(models.Model): |
||||
|
_inherit = 'tier.definition' |
||||
|
|
||||
|
python_code = fields.Text( |
||||
|
string='Tier Definition Expression', |
||||
|
help="Write Python code that defines when this tier confirmation " |
||||
|
"will be needed. The result of executing the expresion must be " |
||||
|
"a boolean.", |
||||
|
default="""# Available locals:\n# - rec: current record""", |
||||
|
) |
||||
|
definition_type = fields.Selection( |
||||
|
selection_add=[('formula', 'Formula')] |
||||
|
) |
||||
|
reviewer_expression = fields.Text( |
||||
|
string='Review Expression', |
||||
|
help="Write Python code that defines the reviewer. " |
||||
|
"The result of executing the expression must be a res.users " |
||||
|
"recordset.", |
||||
|
default="# Available locals:\n# - rec: current record\n" |
||||
|
"# - Expects a recordset of res.users", |
||||
|
) |
||||
|
review_type = fields.Selection( |
||||
|
selection_add=[("expression", "Python Expression")] |
||||
|
) |
||||
|
|
||||
|
@api.onchange('review_type') |
||||
|
def onchange_review_type(self): |
||||
|
super(TierDefinition, self).onchange_review_type() |
||||
|
self.reviewer_expression = "# Available locals:\n" \ |
||||
|
"# - rec: current record\n" \ |
||||
|
"# - Expects a recordset of res.users" |
@ -0,0 +1,47 @@ |
|||||
|
# Copyright 2019 Eficent Business and IT Consulting Services S.L. |
||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from odoo import api, fields, models, _ |
||||
|
from odoo.exceptions import UserError |
||||
|
from odoo.tools.safe_eval import safe_eval |
||||
|
|
||||
|
|
||||
|
class TierReview(models.Model): |
||||
|
_inherit = "tier.review" |
||||
|
|
||||
|
python_reviewer_ids = fields.Many2many( |
||||
|
string="Reviewers from Python expression", comodel_name="res.users", |
||||
|
compute="_compute_python_reviewer_ids", store=True |
||||
|
) |
||||
|
|
||||
|
@api.model |
||||
|
def _get_reviewer_fields(self): |
||||
|
res = super()._get_reviewer_fields() |
||||
|
return res + ['python_reviewer_ids'] |
||||
|
|
||||
|
def _get_reviewers(self): |
||||
|
return super()._get_reviewers() + self.python_reviewer_ids |
||||
|
|
||||
|
@api.multi |
||||
|
@api.depends('definition_id.reviewer_expression', |
||||
|
'review_type', 'model', 'res_id') |
||||
|
def _compute_python_reviewer_ids(self): |
||||
|
for rec in self: |
||||
|
if rec.review_type == 'expression': |
||||
|
record = rec.env[rec.model].browse(rec.res_id).exists() |
||||
|
try: |
||||
|
reviewer_ids = safe_eval( |
||||
|
rec.definition_id.reviewer_expression, |
||||
|
globals_dict={'rec': record}) |
||||
|
except Exception as error: |
||||
|
raise UserError(_( |
||||
|
"Error evaluating tier validation " |
||||
|
"conditions.\n %s") % error) |
||||
|
# Check if python expression returns 'res.users' recordset |
||||
|
if not isinstance(reviewer_ids, models.Model) or \ |
||||
|
reviewer_ids._name != 'res.users': |
||||
|
raise UserError(_( |
||||
|
"Reviewer python expression must return a " |
||||
|
"res.users recordset.")) |
||||
|
else: |
||||
|
rec.python_reviewer_ids = reviewer_ids |
@ -0,0 +1,25 @@ |
|||||
|
# Copyright 2019 Creu Blanca |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from odoo import api, models, _ |
||||
|
from odoo.tools.safe_eval import safe_eval |
||||
|
from odoo.exceptions import UserError |
||||
|
|
||||
|
|
||||
|
class TierValidation(models.AbstractModel): |
||||
|
_inherit = 'tier.validation' |
||||
|
|
||||
|
@api.multi |
||||
|
def evaluate_formula_tier(self, tier): |
||||
|
try: |
||||
|
res = safe_eval(tier.python_code, globals_dict={'rec': self}) |
||||
|
except Exception as error: |
||||
|
raise UserError(_( |
||||
|
"Error evaluating tier validation conditions.\n %s") % error) |
||||
|
return res |
||||
|
|
||||
|
@api.multi |
||||
|
def evaluate_tier(self, tier): |
||||
|
if tier.definition_type == 'formula': |
||||
|
return self.evaluate_formula_tier(tier) |
||||
|
return super().evaluate_tier(tier) |
@ -0,0 +1,2 @@ |
|||||
|
* Enric Tobella <etobella@creublanca.es> |
||||
|
* Adrià Gil Sorribes <adria.gil@eficent.com> |
@ -0,0 +1,2 @@ |
|||||
|
This module includes the ability to define the tier definition domain |
||||
|
and the tier reviewers using python code. |
@ -0,0 +1,2 @@ |
|||||
|
To define the domain by python code choose the Formula option in the Definition field. |
||||
|
To define the reviewers by python code choose Python Expression option in the Validated by field. |
After Width: 128 | Height: 128 | Size: 9.2 KiB |
@ -0,0 +1,405 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8" ?> |
||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
||||
|
<head> |
||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
||||
|
<meta name="generator" content="Docutils 0.12: http://docutils.sourceforge.net/" /> |
||||
|
<title>Base Tier Validation Formula</title> |
||||
|
<style type="text/css"> |
||||
|
|
||||
|
/* |
||||
|
:Author: David Goodger (goodger@python.org) |
||||
|
:Id: $Id: html4css1.css 7614 2013-02-21 15:55:51Z milde $ |
||||
|
:Copyright: This stylesheet has been placed in the public domain. |
||||
|
|
||||
|
Default cascading style sheet for the HTML output of Docutils. |
||||
|
|
||||
|
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to |
||||
|
customize this style sheet. |
||||
|
*/ |
||||
|
|
||||
|
/* used to remove borders from tables and images */ |
||||
|
.borderless, table.borderless td, table.borderless th { |
||||
|
border: 0 } |
||||
|
|
||||
|
table.borderless td, table.borderless th { |
||||
|
/* Override padding for "table.docutils td" with "! important". |
||||
|
The right padding separates the table cells. */ |
||||
|
padding: 0 0.5em 0 0 ! important } |
||||
|
|
||||
|
.first { |
||||
|
/* Override more specific margin styles with "! important". */ |
||||
|
margin-top: 0 ! important } |
||||
|
|
||||
|
.last, .with-subtitle { |
||||
|
margin-bottom: 0 ! important } |
||||
|
|
||||
|
.hidden { |
||||
|
display: none } |
||||
|
|
||||
|
a.toc-backref { |
||||
|
text-decoration: none ; |
||||
|
color: black } |
||||
|
|
||||
|
blockquote.epigraph { |
||||
|
margin: 2em 5em ; } |
||||
|
|
||||
|
dl.docutils dd { |
||||
|
margin-bottom: 0.5em } |
||||
|
|
||||
|
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] { |
||||
|
overflow: hidden; |
||||
|
} |
||||
|
|
||||
|
/* Uncomment (and remove this text!) to get bold-faced definition list terms |
||||
|
dl.docutils dt { |
||||
|
font-weight: bold } |
||||
|
*/ |
||||
|
|
||||
|
div.abstract { |
||||
|
margin: 2em 5em } |
||||
|
|
||||
|
div.abstract p.topic-title { |
||||
|
font-weight: bold ; |
||||
|
text-align: center } |
||||
|
|
||||
|
div.admonition, div.attention, div.caution, div.danger, div.error, |
||||
|
div.hint, div.important, div.note, div.tip, div.warning { |
||||
|
margin: 2em ; |
||||
|
border: medium outset ; |
||||
|
padding: 1em } |
||||
|
|
||||
|
div.admonition p.admonition-title, div.hint p.admonition-title, |
||||
|
div.important p.admonition-title, div.note p.admonition-title, |
||||
|
div.tip p.admonition-title { |
||||
|
font-weight: bold ; |
||||
|
font-family: sans-serif } |
||||
|
|
||||
|
div.attention p.admonition-title, div.caution p.admonition-title, |
||||
|
div.danger p.admonition-title, div.error p.admonition-title, |
||||
|
div.warning p.admonition-title, .code .error { |
||||
|
color: red ; |
||||
|
font-weight: bold ; |
||||
|
font-family: sans-serif } |
||||
|
|
||||
|
/* Uncomment (and remove this text!) to get reduced vertical space in |
||||
|
compound paragraphs. |
||||
|
div.compound .compound-first, div.compound .compound-middle { |
||||
|
margin-bottom: 0.5em } |
||||
|
|
||||
|
div.compound .compound-last, div.compound .compound-middle { |
||||
|
margin-top: 0.5em } |
||||
|
*/ |
||||
|
|
||||
|
div.dedication { |
||||
|
margin: 2em 5em ; |
||||
|
text-align: center ; |
||||
|
font-style: italic } |
||||
|
|
||||
|
div.dedication p.topic-title { |
||||
|
font-weight: bold ; |
||||
|
font-style: normal } |
||||
|
|
||||
|
div.figure { |
||||
|
margin-left: 2em ; |
||||
|
margin-right: 2em } |
||||
|
|
||||
|
div.footer, div.header { |
||||
|
clear: both; |
||||
|
font-size: smaller } |
||||
|
|
||||
|
div.line-block { |
||||
|
display: block ; |
||||
|
margin-top: 1em ; |
||||
|
margin-bottom: 1em } |
||||
|
|
||||
|
div.line-block div.line-block { |
||||
|
margin-top: 0 ; |
||||
|
margin-bottom: 0 ; |
||||
|
margin-left: 1.5em } |
||||
|
|
||||
|
div.sidebar { |
||||
|
margin: 0 0 0.5em 1em ; |
||||
|
border: medium outset ; |
||||
|
padding: 1em ; |
||||
|
background-color: #ffffee ; |
||||
|
width: 40% ; |
||||
|
float: right ; |
||||
|
clear: right } |
||||
|
|
||||
|
div.sidebar p.rubric { |
||||
|
font-family: sans-serif ; |
||||
|
font-size: medium } |
||||
|
|
||||
|
div.system-messages { |
||||
|
margin: 5em } |
||||
|
|
||||
|
div.system-messages h1 { |
||||
|
color: red } |
||||
|
|
||||
|
div.system-message { |
||||
|
border: medium outset ; |
||||
|
padding: 1em } |
||||
|
|
||||
|
div.system-message p.system-message-title { |
||||
|
color: red ; |
||||
|
font-weight: bold } |
||||
|
|
||||
|
div.topic { |
||||
|
margin: 2em } |
||||
|
|
||||
|
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle, |
||||
|
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle { |
||||
|
margin-top: 0.4em } |
||||
|
|
||||
|
h1.title { |
||||
|
text-align: center } |
||||
|
|
||||
|
h2.subtitle { |
||||
|
text-align: center } |
||||
|
|
||||
|
hr.docutils { |
||||
|
width: 75% } |
||||
|
|
||||
|
img.align-left, .figure.align-left, object.align-left { |
||||
|
clear: left ; |
||||
|
float: left ; |
||||
|
margin-right: 1em } |
||||
|
|
||||
|
img.align-right, .figure.align-right, object.align-right { |
||||
|
clear: right ; |
||||
|
float: right ; |
||||
|
margin-left: 1em } |
||||
|
|
||||
|
img.align-center, .figure.align-center, object.align-center { |
||||
|
display: block; |
||||
|
margin-left: auto; |
||||
|
margin-right: auto; |
||||
|
} |
||||
|
|
||||
|
.align-left { |
||||
|
text-align: left } |
||||
|
|
||||
|
.align-center { |
||||
|
clear: both ; |
||||
|
text-align: center } |
||||
|
|
||||
|
.align-right { |
||||
|
text-align: right } |
||||
|
|
||||
|
/* reset inner alignment in figures */ |
||||
|
div.align-right { |
||||
|
text-align: inherit } |
||||
|
|
||||
|
/* div.align-center * { */ |
||||
|
/* text-align: left } */ |
||||
|
|
||||
|
ol.simple, ul.simple { |
||||
|
margin-bottom: 1em } |
||||
|
|
||||
|
ol.arabic { |
||||
|
list-style: decimal } |
||||
|
|
||||
|
ol.loweralpha { |
||||
|
list-style: lower-alpha } |
||||
|
|
||||
|
ol.upperalpha { |
||||
|
list-style: upper-alpha } |
||||
|
|
||||
|
ol.lowerroman { |
||||
|
list-style: lower-roman } |
||||
|
|
||||
|
ol.upperroman { |
||||
|
list-style: upper-roman } |
||||
|
|
||||
|
p.attribution { |
||||
|
text-align: right ; |
||||
|
margin-left: 50% } |
||||
|
|
||||
|
p.caption { |
||||
|
font-style: italic } |
||||
|
|
||||
|
p.credits { |
||||
|
font-style: italic ; |
||||
|
font-size: smaller } |
||||
|
|
||||
|
p.label { |
||||
|
white-space: nowrap } |
||||
|
|
||||
|
p.rubric { |
||||
|
font-weight: bold ; |
||||
|
font-size: larger ; |
||||
|
color: maroon ; |
||||
|
text-align: center } |
||||
|
|
||||
|
p.sidebar-title { |
||||
|
font-family: sans-serif ; |
||||
|
font-weight: bold ; |
||||
|
font-size: larger } |
||||
|
|
||||
|
p.sidebar-subtitle { |
||||
|
font-family: sans-serif ; |
||||
|
font-weight: bold } |
||||
|
|
||||
|
p.topic-title { |
||||
|
font-weight: bold } |
||||
|
|
||||
|
pre.address { |
||||
|
margin-bottom: 0 ; |
||||
|
margin-top: 0 ; |
||||
|
font: inherit } |
||||
|
|
||||
|
pre.literal-block, pre.doctest-block, pre.math, pre.code { |
||||
|
margin-left: 2em ; |
||||
|
margin-right: 2em } |
||||
|
|
||||
|
pre.code .ln { color: grey; } /* line numbers */ |
||||
|
pre.code, code { background-color: #eeeeee } |
||||
|
pre.code .comment, code .comment { color: #5C6576 } |
||||
|
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } |
||||
|
pre.code .literal.string, code .literal.string { color: #0C5404 } |
||||
|
pre.code .name.builtin, code .name.builtin { color: #352B84 } |
||||
|
pre.code .deleted, code .deleted { background-color: #DEB0A1} |
||||
|
pre.code .inserted, code .inserted { background-color: #A3D289} |
||||
|
|
||||
|
span.classifier { |
||||
|
font-family: sans-serif ; |
||||
|
font-style: oblique } |
||||
|
|
||||
|
span.classifier-delimiter { |
||||
|
font-family: sans-serif ; |
||||
|
font-weight: bold } |
||||
|
|
||||
|
span.interpreted { |
||||
|
font-family: sans-serif } |
||||
|
|
||||
|
span.option { |
||||
|
white-space: nowrap } |
||||
|
|
||||
|
span.pre { |
||||
|
white-space: pre } |
||||
|
|
||||
|
span.problematic { |
||||
|
color: red } |
||||
|
|
||||
|
span.section-subtitle { |
||||
|
/* font-size relative to parent (h1..h6 element) */ |
||||
|
font-size: 80% } |
||||
|
|
||||
|
table.citation { |
||||
|
border-left: solid 1px gray; |
||||
|
margin-left: 1px } |
||||
|
|
||||
|
table.docinfo { |
||||
|
margin: 2em 4em } |
||||
|
|
||||
|
table.docutils { |
||||
|
margin-top: 0.5em ; |
||||
|
margin-bottom: 0.5em } |
||||
|
|
||||
|
table.footnote { |
||||
|
border-left: solid 1px black; |
||||
|
margin-left: 1px } |
||||
|
|
||||
|
table.docutils td, table.docutils th, |
||||
|
table.docinfo td, table.docinfo th { |
||||
|
padding-left: 0.5em ; |
||||
|
padding-right: 0.5em ; |
||||
|
vertical-align: top } |
||||
|
|
||||
|
table.docutils th.field-name, table.docinfo th.docinfo-name { |
||||
|
font-weight: bold ; |
||||
|
text-align: left ; |
||||
|
white-space: nowrap ; |
||||
|
padding-left: 0 } |
||||
|
|
||||
|
/* "booktabs" style (no vertical lines) */ |
||||
|
table.docutils.booktabs { |
||||
|
border: 0px; |
||||
|
border-top: 2px solid; |
||||
|
border-bottom: 2px solid; |
||||
|
border-collapse: collapse; |
||||
|
} |
||||
|
table.docutils.booktabs * { |
||||
|
border: 0px; |
||||
|
} |
||||
|
table.docutils.booktabs th { |
||||
|
border-bottom: thin solid; |
||||
|
text-align: left; |
||||
|
} |
||||
|
|
||||
|
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils, |
||||
|
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils { |
||||
|
font-size: 100% } |
||||
|
|
||||
|
ul.auto-toc { |
||||
|
list-style-type: none } |
||||
|
|
||||
|
</style> |
||||
|
</head> |
||||
|
<body> |
||||
|
<div class="document" id="base-tier-validation-formula"> |
||||
|
<h1 class="title">Base Tier Validation Formula</h1> |
||||
|
|
||||
|
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
||||
|
!! This file is generated by oca-gen-addon-readme !! |
||||
|
!! changes will be overwritten. !! |
||||
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> |
||||
|
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/server-ux/tree/11.0/base_tier_validation_formula"><img alt="OCA/server-ux" src="https://img.shields.io/badge/github-OCA%2Fserver--ux-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/server-ux-11-0/server-ux-11-0-base_tier_validation_formula"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/250/11.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p> |
||||
|
<p>This module includes the ability to define the tier definition domain |
||||
|
and the tier reviewers using python code.</p> |
||||
|
<p><strong>Table of contents</strong></p> |
||||
|
<div class="contents local topic" id="contents"> |
||||
|
<ul class="simple"> |
||||
|
<li><a class="reference internal" href="#usage" id="id1">Usage</a></li> |
||||
|
<li><a class="reference internal" href="#bug-tracker" id="id2">Bug Tracker</a></li> |
||||
|
<li><a class="reference internal" href="#credits" id="id3">Credits</a><ul> |
||||
|
<li><a class="reference internal" href="#authors" id="id4">Authors</a></li> |
||||
|
<li><a class="reference internal" href="#contributors" id="id5">Contributors</a></li> |
||||
|
<li><a class="reference internal" href="#maintainers" id="id6">Maintainers</a></li> |
||||
|
</ul> |
||||
|
</li> |
||||
|
</ul> |
||||
|
</div> |
||||
|
<div class="section" id="usage"> |
||||
|
<h1><a class="toc-backref" href="#id1">Usage</a></h1> |
||||
|
<p>To define the domain by python code choose the Formula option in the Definition field. |
||||
|
To define the reviewers by python code choose Python Expression option in the Validated by field.</p> |
||||
|
</div> |
||||
|
<div class="section" id="bug-tracker"> |
||||
|
<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1> |
||||
|
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-ux/issues">GitHub Issues</a>. |
||||
|
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 |
||||
|
<a class="reference external" href="https://github.com/OCA/server-ux/issues/new?body=module:%20base_tier_validation_formula%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p> |
||||
|
<p>Do not contact contributors directly about support or help with technical issues.</p> |
||||
|
</div> |
||||
|
<div class="section" id="credits"> |
||||
|
<h1><a class="toc-backref" href="#id3">Credits</a></h1> |
||||
|
<div class="section" id="authors"> |
||||
|
<h2><a class="toc-backref" href="#id4">Authors</a></h2> |
||||
|
<ul class="simple"> |
||||
|
<li>Creu Blanca</li> |
||||
|
</ul> |
||||
|
</div> |
||||
|
<div class="section" id="contributors"> |
||||
|
<h2><a class="toc-backref" href="#id5">Contributors</a></h2> |
||||
|
<ul class="simple"> |
||||
|
<li>Enric Tobella <<a class="reference external" href="mailto:etobella@creublanca.es">etobella@creublanca.es</a>></li> |
||||
|
<li>Adrià Gil Sorribes <<a class="reference external" href="mailto:adria.gil@eficent.com">adria.gil@eficent.com</a>></li> |
||||
|
</ul> |
||||
|
</div> |
||||
|
<div class="section" id="maintainers"> |
||||
|
<h2><a class="toc-backref" href="#id6">Maintainers</a></h2> |
||||
|
<p>This module is maintained by the OCA.</p> |
||||
|
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a> |
||||
|
<p>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.</p> |
||||
|
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-ux/tree/11.0/base_tier_validation_formula">OCA/server-ux</a> project on GitHub.</p> |
||||
|
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</body> |
||||
|
</html> |
@ -0,0 +1,4 @@ |
|||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from . import common |
||||
|
from . import test_tier_validation |
@ -0,0 +1,19 @@ |
|||||
|
# Copyright 2018 Eficent Business and IT Consulting Services S.L. |
||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
|
||||
|
def setup_test_model(env, model_clses): |
||||
|
for model_cls in model_clses: |
||||
|
model_cls._build_model(env.registry, env.cr) |
||||
|
|
||||
|
env.registry.setup_models(env.cr) |
||||
|
env.registry.init_models( |
||||
|
env.cr, [model_cls._name for model_cls in model_clses], |
||||
|
dict(env.context, update_custom_fields=True) |
||||
|
) |
||||
|
|
||||
|
|
||||
|
def teardown_test_model(env, model_clses): |
||||
|
for model_cls in model_clses: |
||||
|
del env.registry.models[model_cls._name] |
||||
|
env.registry.setup_models(env.cr) |
@ -0,0 +1,112 @@ |
|||||
|
# Copyright 2018 Eficent Business and IT Consulting Services S.L. |
||||
|
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). |
||||
|
|
||||
|
from odoo.tests import common |
||||
|
from odoo.exceptions import UserError |
||||
|
from .common import setup_test_model, teardown_test_model |
||||
|
from .tier_validation_tester import TierValidationTester |
||||
|
|
||||
|
|
||||
|
@common.at_install(False) |
||||
|
@common.post_install(True) |
||||
|
class TierTierValidation(common.SavepointCase): |
||||
|
|
||||
|
@classmethod |
||||
|
def setUpClass(cls): |
||||
|
super(TierTierValidation, cls).setUpClass() |
||||
|
|
||||
|
setup_test_model(cls.env, [TierValidationTester]) |
||||
|
|
||||
|
cls.test_model = cls.env[TierValidationTester._name] |
||||
|
|
||||
|
cls.tester_model = cls.env['ir.model'].search([ |
||||
|
('model', '=', 'tier.validation.tester')]) |
||||
|
|
||||
|
# Access record: |
||||
|
cls.env["ir.model.access"].create({ |
||||
|
'name': "access.tester", |
||||
|
'model_id': cls.tester_model.id, |
||||
|
'perm_read': 1, |
||||
|
'perm_write': 1, |
||||
|
'perm_create': 1, |
||||
|
'perm_unlink': 1, |
||||
|
}) |
||||
|
|
||||
|
# Create users: |
||||
|
group_ids = cls.env.ref('base.group_system').ids |
||||
|
cls.test_user_1 = cls.env['res.users'].create({ |
||||
|
'name': 'John', |
||||
|
'login': 'test1', |
||||
|
'groups_id': [(6, 0, group_ids)], |
||||
|
}) |
||||
|
cls.test_user_2 = cls.env['res.users'].create({ |
||||
|
'name': 'Mike', |
||||
|
'login': 'test2', |
||||
|
}) |
||||
|
cls.test_user_3 = cls.env['res.users'].create({ |
||||
|
'name': 'Mary', |
||||
|
'login': 'test3', |
||||
|
}) |
||||
|
|
||||
|
# Create tier definitions: |
||||
|
cls.tier_def_obj = cls.env['tier.definition'] |
||||
|
cls.tier_def_obj.create({ |
||||
|
'model_id': cls.tester_model.id, |
||||
|
'review_type': 'individual', |
||||
|
'reviewer_id': cls.test_user_1.id, |
||||
|
'definition_domain': "[('test_field', '>', 1.0)]", |
||||
|
}) |
||||
|
|
||||
|
cls.test_record = cls.test_model.create({ |
||||
|
'test_field': 2.5, |
||||
|
}) |
||||
|
|
||||
|
@classmethod |
||||
|
def tearDownClass(cls): |
||||
|
teardown_test_model(cls.env, |
||||
|
[TierValidationTester]) |
||||
|
super(TierTierValidation, cls).tearDownClass() |
||||
|
|
||||
|
def test_01_reviewer_from_python_expression(self): |
||||
|
tier_definition = self.tier_def_obj.create({ |
||||
|
'model_id': self.tester_model.id, |
||||
|
'review_type': 'individual', |
||||
|
'reviewer_id': self.test_user_1.id, |
||||
|
'definition_type': 'formula', |
||||
|
'python_code': 'rec.test_field > 1.0', |
||||
|
}) |
||||
|
tier_definition.write({ |
||||
|
'model_id': self.tester_model.id, |
||||
|
'review_type': 'expression', |
||||
|
'python_code': 'rec.test_field > 3.0', |
||||
|
}) |
||||
|
tier_definition.onchange_review_type() |
||||
|
tier_definition.write({ |
||||
|
'reviewer_expression': 'rec.user_id', |
||||
|
}) |
||||
|
self.test_record.write({ |
||||
|
'test_field': 3.5, |
||||
|
'user_id': self.test_user_2.id, |
||||
|
}) |
||||
|
reviews = self.test_record.sudo( |
||||
|
self.test_user_3.id).request_validation() |
||||
|
self.assertTrue(reviews) |
||||
|
self.assertEqual(len(reviews), 2) |
||||
|
record = self.test_record.sudo(self.test_user_1.id) |
||||
|
self.assertIn(self.test_user_1, record.reviewer_ids) |
||||
|
self.assertIn(self.test_user_2, record.reviewer_ids) |
||||
|
res = self.test_model.search( |
||||
|
[('reviewer_ids', 'in', self.test_user_2.id)]) |
||||
|
self.assertTrue(res) |
||||
|
|
||||
|
def test_02_wrong_reviewer_expression(self): |
||||
|
"""Error should raise with incorrect python expresions on |
||||
|
tier definitions.""" |
||||
|
self.tier_def_obj.create({ |
||||
|
'model_id': self.tester_model.id, |
||||
|
'review_type': 'expression', |
||||
|
'reviewer_expression': 'rec.test_field', |
||||
|
'python_code': 'rec.test_field > 1.0', |
||||
|
}) |
||||
|
with self.assertRaises(UserError): |
||||
|
self.test_record.sudo(self.test_user_3.id).request_validation() |
@ -0,0 +1,23 @@ |
|||||
|
# Copyright 2018 Eficent Business and IT Consulting Services S.L. |
||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from odoo import api, fields, models |
||||
|
|
||||
|
|
||||
|
class TierValidationTester(models.Model): |
||||
|
_name = 'tier.validation.tester' |
||||
|
_inherit = ['tier.validation'] |
||||
|
|
||||
|
state = fields.Selection( |
||||
|
selection=[('draft', 'Draft'), |
||||
|
('confirmed', 'Confirmed'), |
||||
|
('cancel', 'Cancel')], |
||||
|
default='draft', |
||||
|
) |
||||
|
test_field = fields.Float() |
||||
|
user_id = fields.Many2one(string="Assigned to:", |
||||
|
comodel_name="res.users") |
||||
|
|
||||
|
@api.multi |
||||
|
def action_confirm(self): |
||||
|
self.write({'state': 'confirmed'}) |
@ -0,0 +1,25 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<!-- Copyright 2017 Eficent Business and IT Consulting Services S.L. |
||||
|
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> |
||||
|
<odoo> |
||||
|
|
||||
|
<record id="tier_definition_view_form" model="ir.ui.view"> |
||||
|
<field name="name">tier.definition.form</field> |
||||
|
<field name="model">tier.definition</field> |
||||
|
<field name="inherit_id" |
||||
|
ref="base_tier_validation.tier_definition_view_form"/> |
||||
|
<field name="arch" type="xml"> |
||||
|
<xpath expr="//form/sheet/group" position="after"> |
||||
|
<group col="4"> |
||||
|
<field name="reviewer_expression" colspan="4" |
||||
|
attrs="{'invisible': [('review_type', '!=', 'expression')]}"/> |
||||
|
</group> |
||||
|
</xpath> |
||||
|
<field name="definition_domain" position="after"> |
||||
|
<field name="python_code" |
||||
|
attrs="{'invisible': [('definition_type', '!=', 'formula')]}"/> |
||||
|
</field> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
</odoo> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue