1.原有效果截图
https://img-blog.csdnimg.cn/211b9e64b55946c89d5cdc004e4e57c5.png
2.实现后的效果
3.在原有视图上增加不少内容,并且增加修改字段按钮,国内关于这方面的文档有点少,要研究一会才实现,
4,在原有模型上继续,增加字段
代码语言:javascript复制from odoo import api, models, fields
class InheritMailActivity(models.Model):
_inherit = 'mail.activity'
progress = fields.Float('Progress')
importance = fields.Selection([
('a', 'Low'), ('aa', 'Medium'),
('aaa', 'High'), ('aaaa', 'Highest'), ('aaaaa', 'MHighest')],
'Importance', default='a')
def _default_task(self):
context = self.env.context
model = context.get('default_res_model')
res_id = context.get('default_res_id')
from_model = self.env[model].sudo().browse(res_id)
if model == 'sale.requirement.quotation':
return from_model.name
def _default_ref_no(self):
context = self.env.context
model = context.get('default_res_model')
res_id = context.get('default_res_id')
from_model = self.env[model].sudo().browse(res_id)
obj = {
'sale.requirement.quotation':'order_ref',
'sale.requirement':'order_ref',
}
if model == 'sale.requirement.quotation':
return from_model.order_ref
task = fields.Char('Task', default=_default_task)
ref_no = fields.Char('Ref No', default=_default_ref_no)
special_task = fields.Char('Special Task')
submitter = fields.Char('Submitter')
is_task = fields.Boolean('Is Task')
def get_importance(self):
arr = []
for rec in self:
for item in range(1,int(rec.importance)):
arr.append(item)
return arr
5.找到他们的原来的实现js文件
https://img-blog.csdnimg.cn/20c299e3202c42e496b1e149af434cd0.png
6,在他们基础实现继承和修改,本来使用extend 和include 来 实现继承 js 修改进度弹窗的功能发现,最后直接在原型上继承
代码语言:javascript复制odoo.define('quotation_information.extend_thread', function (require) {
var Activity = require('mail.Activity');
Activity.prototype.events[ 'click .o_activity_progress_edit'] = 'progressEdit'
Activity.prototype.progressEdit =function(event,options){
event.preventDefault();
var self = this;
var activity_id = $(event.currentTarget).data('activity-id');
var progress = $(event.currentTarget).text()
var action = _.defaults(options || {}, {
type: 'ir.actions.act_window',
res_model: 'product.quotation.qta',
view_mode: 'form',
view_type: 'form',
views: [[false, 'form']],
target: 'new',
views_id:'email_progress_update',
context: {
default_active_ids: activity_id,
default_progress:parseInt(progress),
default_res_model: 'product.quotation.qta',
},
// res_id: activity_id,
});
return this.do_action(action, {
on_close: function () {
self._reload();
},
});
}
})
6.form视图的继承代码 xml,
代码语言:javascript复制<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<!-- Planned activities 的展示修改-->
<t t-extend="mail.activity_items">
<t t-jquery="div#o_chatter_planned_activities a.o_activity_info" t-operation="before">
<t t-if="activity.user_quotation_ids">
<t t-foreach="activity.user_quotation_ids" t-as="user_id">
<t t-esc="user_id[1]"/>
</t>
</t>
</t>
</t>
<t t-extend="mail.activity_items">
<t t-jquery="div#o_chatter_planned_activities div.o_thread_message_tools" t-operation="before">
<div style="display:flex">
<strong><span t-attf-class="o_activity_date o_activity_color_#{activity.state}"><t t-esc="activity.label_delay" /></span></strong>
<span style="margin: 0 10px;">截止日期:<t t-esc="activity.date_deadline.format(datetime_format)" /></span>
<div style="display: flex;">进度:<div class="progress" style="width:300px">
<div class="progress-bar progress-bar-warning" role="progressbar" t-att-aria-valuenow="activity.progress" aria-valuemin="0" aria-valuemax="100" t-attf-style="width: {{activity.progress}}%;">
<t t-esc="activity.progress" /> %
</div>
</div> </div>
</div>
<div style="display:flex">
<span > 重要程度:
<span style="position:relative">
<span>
<span t-foreach="[1,2,3,4,5]" t-as="item" class="glyphicon glyphicon-star-empty" style="color:yellow" > </span>
</span>
<span style="color:yellow;position: absolute;left:0;top:0">
<span t-foreach="activity.importance" t-as="item" class="glyphicon glyphicon-star" > </span>
</span>
</span>
</span>
<span style="margin-left:10px" t-if="activity.special_task">
特殊任务:<t t-esc="activity.special_task or ''"/>
</span>
<span t-else="" style="margin-left:10px">
职能任务
</span>
</div>
</t>
<t t-jquery="div#o_chatter_planned_activities a.o_activity_edit" t-operation="after">
<a href="#" class="btn btn-link btn-default text-muted btn-sm o_activity_progress_edit o_activity_link" t-att-data-progress="activity.progress" t-att-data-activity-id="activity.id">
<i class="fa fa-pencil"/> Edit Progress
</a>
</t>
</t>
</templates>
7.总结,Odoo 是一个十分强大的Erp系统,但是文档不全,学习起来费劲。