在Odoo13中,可以通过自定义模块来实现使satusbar仅对特定状态可裁剪的功能。以下是一种实现方式:
from odoo import models, fields
class CustomModel(models.Model):
_name = 'custom.model'
_description = 'Custom Model'
name = fields.Char(string='Name')
status = fields.Selection([
('draft', 'Draft'),
('confirmed', 'Confirmed'),
('done', 'Done')
], string='Status', default='draft')
<odoo>
<data>
<record model="ir.ui.view" id="custom_model_form_view">
<field name="name">custom.model.form.view</field>
<field name="model">custom.model</field>
<field name="arch" type="xml">
<form>
<header>
<button name="%(action_confirm)d" string="Confirm" states="draft" class="oe_highlight"/>
<button name="%(action_done)d" string="Done" states="confirmed" class="oe_highlight"/>
</header>
<sheet>
<!-- Your fields here -->
</sheet>
</form>
</field>
</record>
</data>
</odoo>
from odoo import http
from odoo.http import request
class CustomController(http.Controller):
@http.route('/custom/model/<int:model_id>/confirm', type='json', auth='user')
def action_confirm(self, model_id):
model = request.env['custom.model'].browse(model_id)
model.write({'status': 'confirmed'})
return True
@http.route('/custom/model/<int:model_id>/done', type='json', auth='user')
def action_done(self, model_id):
model = request.env['custom.model'].browse(model_id)
model.write({'status': 'done'})
return True
<odoo>
<data>
<record id="custom_model_security_rule" model="ir.rule">
<field name="name">Custom Model Security Rule</field>
<field name="model_id" ref="model_custom_model"/>
<field name="domain_force">[('status', 'in', ['draft', 'confirmed'])]</field>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
<field name="perm_create" eval="True"/>
<field name="perm_unlink" eval="True"/>
</record>
</data>
</odoo>
{
'name': 'Custom Module',
'version': '1.0',
'summary': 'Custom Module Summary',
'description': 'Custom Module Description',
'author': 'Your Name',
'depends': ['base'],
'data': [
'security.xml',
'views.xml',
],
'demo': [],
'installable': True,
'application': True,
}
这样,您就可以使status bar仅对特定状态可裁剪,并根据状态的变化显示或隐藏相关按钮。请注意,以上示例中的代码仅供参考,您可以根据实际需求进行修改和扩展。
领取专属 10元无门槛券
手把手带您无忧上云