欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

odoo部分知识点注解

程序员文章站 2024-02-04 21:27:28
...

bugmanger和quality部分代码解析

一.按钮的动作
1.1bug.py

 class Bug(models.Model):
 _name='bm.bug'
_description='bug'
name=fields.Char('bug简述',required=True)
detail=fields.Text(size=150)
is_closed=fields.Boolean('是否关闭')
close_reason=fields.Selection([('changed','已修改'),('cannot','无法修改'),('delay','推迟')],string='关闭理由')
user_id=fields.Many2one('res.users',string='负责人')
follower_id=fields.Many2many('res.partner',string='关注者')

var foo = ‘bar’;

@api.multi
def do_close(self):
    for item in self:
        item.is_closed=True
    return True

var foo = ‘bar’;
1.2bugs.xml

      <header>
          <button name="do_close" type="object" string="关闭bug"/>
      </header>

var foo = ‘bar’;
1.3前台
odoo部分知识点注解
点关闭bug,是否关闭打钩表示关闭;

二.负责人和关注人员的引用
1.1bugs.py

from odoo import models, fields, api
class Bug(models.Model):
_name='bm.bug'
_description='bug'
name=fields.Char('bug简述',required=True)
detail=fields.Text(size=150)
is_closed=fields.Boolean('是否关闭')
close_reason=fields.Selection([('changed','已修改'),('cannot','无法修改'),('delay','推迟')],string='关闭理由')
user_id=fields.Many2one('res.users',string='负责人')
follower_id=fields.Many2many('res.partner',string='关注者')
 var foo = 'bar';

2.2bugs.xml

          <group name="group_top" col="2">
              <group name="group_left">
                  <field name="name"/>
                  <field name="user_id"/>
                  <field name="is_closed"/>
              </group>
              <group name="group_right">
                  <field name="close_reason"/>
                  <field name="follower_id"/>
              </group>
       var foo = 'bar';

2.3前端
odoo部分知识点注解

三.引用base.view_partner_form表单
3.1follower.py
from odoo import models, fields, api

class follower(models.Model):
_inherit=‘res.partner’
bug_ids=fields.Many2many(‘bm.bug’,string=‘bug’)
3.2follower.xml

      <record model="ir.ui.view" id="bug-manage.follower_form">
      <field name="name">follower</field>
      <field name="model">res.partner</field>
      <field name="inherit_id" ref="base.view_partner_form"/>
      <field name="arch" type="xml">
        <field name="mobile" position="after">
            <field name="bug_ids"/>
        </field>
      </field>
    </record>
    <!-- actions opening views on models -->
    <record model="ir.actions.act_window" id="bug-manage.follower_action_window">
      <field name="name">follower window</field>
      <field name="res_model">res.partner</field>
      <field name="view_mode">form</field>
    </record>      
  var foo = 'bar';

3.3前端
odoo部分知识点注解

四.向导的设计
4.1bug_wizard.xml

  <odoo>
   <data>
    <record id="bug_wizard" model="ir.ui.view">
        <field name="name">bug管理-向导</field>
        <field name="model">bug.wizard</field>
        <field name="arch" type="xml">
            <form>
                <div class="oe_right">
                    <button type="object" name="count_bugs" string="统计bug数"/>
                    <button type="object" name="get_bugs" string="获取bug"/>
                </div>
                <field name="bug_ids">
                    <tree>
                        <field name="name"/>
                        <field name="user_id"/>
                        <field name="is_closed"/>
                    </tree>
                </field>
                <group>
                    <group><field name="wizard_user_id"/></group>
                    <group><field name="new_is_closed"/></group>
                </group>
                <footer>
                    <button type="object" name="update_batch" string="批量更新" class="oe_highlight"
                            attrs="{'invisible':[('new_is_closed','=',False),('wizard_user_id','=',False)]}"/>
                </footer>
            </form>
        </field>
    </record>

    <act_window id="action_bug_wizard"
                name="bug管理向导"
                src_model="bm.bug"
                res_model="bug.wizard"
                view_mode="form"
                target="new"
                multi="True"/>
</data>
var foo = 'bar'; 4.2前端 ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200208181806709.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L21yYmVsbA==,size_16,color_FFFFFF,t_70)

4.3对应bug.wizard.py中按钮代码
4.3.1
odoo部分知识点注解
以上两个按钮显示
4.3.2
@api.multi
def count_bugs(self):
bug=self.env[‘bm.bug’]
count=bug.search_count([])
raise exceptions.Warning(‘有%d条bug’%count)
odoo部分知识点注解
统计bugs总数量

4.3.3

@api.multi
def get_bugs(self):
    self.ensure_one()
    bug = self.env['bm.bug']
    all_bugs = bug.search([('is_closed', '=', False)])
    # Fill the wizard Task list with all tasks
    self.bug_ids = all_bugs
    # reopen wizard form on same wizard record
    return self.helper_form()

@api.multi
def helper_form(self):
    self.ensure_one()
    return {
        'type': 'ir.actions.act_window',
        'res_model': self._name,  # this model
        'res_id': self.id,  # the current wizard record
        'view_type': 'form',
        'view_mode': 'form',
        'target': 'new'}

odoo部分知识点注解
获取未关闭的bugs

4.3.4批量更新

import logging
_logger=logging.getLogger(__name__)
from odoo import exceptions

  <footer>
 <button type="object" name="update_batch" string="批量更新" class="oe_highlight"
 attrs="{'invisible':[('new_is_closed','=',False),('wizard_user_id','=',False)]}"/>
</footer>

@api.multi
def update_batch(self):
    self.ensure_one()
    if not (self.new_is_closed or self.wizard_user_id):
        raise exceptions.ValidationError('无数据要更新')
    _logger.debug('批量bug更新操作 %s',self.bug_ids.ids)
    vals={}
    if self.new_is_closed:
        vals['is_closed']=self.new_is_closed
    if self.wizard_user_id:
        vals['user_id']=self.wizard_user_id
    if vals:
        self.bug_ids.write(vals)
    return True

var foo = ‘bar’;
odoo部分知识点注解
odoo部分知识点注解
odoo部分知识点注解

相关标签: odoo