2016-11-24 8 views
1

私はカスタムモデル 'product_images.product_image'にOdoo公開ワークフローを実装しようとしています。Odooでのワークフローのモデルの状態

私のモデルは次のようになります。私も切り替えることができますワークフローを作成するためのいくつかのレコードを持っている

<!-- product_images/data/data.xml --> 
<odoo> 
    <data> 
     <!-- explicit list view definition --> 
     <record model="product_images.publishing_status" id="product_images.publishing_status_draft"> 
      <field name="name">Draft</field> 
      <field name="slug">draft</field> 
     </record> 
     <record model="product_images.publishing_status" id="product_images.publishing_status_pending"> 
      <field name="name">Pending</field> 
      <field name="slug">pending</field> 
     </record> 
     <record model="product_images.publishing_status" id="product_images.publishing_status_approved"> 
      <field name="name">Approved</field> 
      <field name="slug">approved</field> 
     </record> 
     <record model="product_images.publishing_status" id="product_images.publishing_status_rejected"> 
      <field name="name">Rejected</field> 
      <field name="slug">rejected</field> 
     </record> 
    </data> 
</odoo> 

# product_images/models/models.py 
# -*- coding: utf-8 -*- 
from odoo import models, fields, api, tools 

class PublishingStatus(models.Model): 
    _name = 'product_images.publishing_status' 
    _description = 'Publishing status' 

    name = fields.Char(string="Name") 
    slug = fields.Char(string="Slug") 


class ProductImage(models.Model): 
    _name = 'product_images.product_image' 
    _description = 'Product image' 

    name = fields.Char(string="Alternative text") 
    product_id = fields.Many2one('product.product', string='Product', ondelete='set null', index=True) 
    original_image = fields.Binary(string='Original image') 

    @api.model 
    def _get_default_state(self): 
     return self.env['product_images.publishing_status'].search([['slug', '=', 'draft']]) 

    @api.model 
    def _get_all_states(self, groups, domain, order): 
     state_ids = self.env['product_images.publishing_status'].search([]) 
     return state_ids 

    state_id = fields.Many2one(
     'product_images.publishing_status', 
     string='Publishing status', 
     default=_get_default_state, 
     group_expand='_get_all_states', 
    ) 

    @api.multi 
    def action_set_to_draft(self): 
     self.state_id = self.env['product_images.publishing_status'].search([['slug', '=', 'draft']]) 

    @api.multi 
    def action_request_for_approval(self): 
     self.state_id = self.env['product_images.publishing_status'].search([['slug', '=', 'pending']]) 

    @api.multi 
    def action_approve(self): 
     self.state_id = self.env['product_images.publishing_status'].search([['slug', '=', 'approved']]) 

    @api.multi 
    def action_reject(self): 
     self.state_id = self.env['product_images.publishing_status'].search([['slug', '=', 'rejected']]) 

それから私は出版状況のためのいくつかのデータレコードを持っています公開ステータス:

<odoo> 
    <data> 
     <record model="workflow" id="product_images.wkf_image_publishing"> 
      <field name="name">Product Image Publishing Workflow</field> 
      <field name="osv">product_images.product_image</field> 
      <field name="on_create">True</field> 
     </record> 

     <record model="workflow.activity" id="product_images.wkf_activity_draft"> 
      <field name="name">Draft</field> 
      <field name="wkf_id" ref="product_images.wkf_image_publishing" /> 
      <field name="flow_start" eval="True" /> 
      <field name="kind">function</field> 
      <field name="action">action_set_to_draft()</field> 
     </record> 
     <record model="workflow.activity" id="product_images.wkf_activity_pending"> 
      <field name="name">Pending</field> 
      <field name="wkf_id" ref="product_images.wkf_image_publishing" /> 
      <field name="kind">function</field> 
      <field name="action">action_request_for_approval()</field> 
     </record> 
     <record model="workflow.activity" id="product_images.wkf_activity_approved"> 
      <field name="name">Approved</field> 
      <field name="wkf_id" ref="product_images.wkf_image_publishing" /> 
      <field name="flow_stop" eval="True" /> 
      <field name="kind">function</field> 
      <field name="action">action_approve()</field> 
     </record> 
     <record model="workflow.activity" id="product_images.wkf_activity_rejected"> 
      <field name="name">Rejected</field> 
      <field name="wkf_id" ref="product_images.wkf_image_publishing" /> 
      <field name="flow_stop" eval="True" /> 
      <field name="kind">function</field> 
      <field name="action">action_reject()</field> 
     </record> 

     <record model="workflow.transition" id="product_images.wkf_transition_draft_to_pending"> 
      <field name="act_from" ref="product_images.wkf_activity_draft" /> 
      <field name="act_to" ref="product_images.wkf_activity_pending" /> 
      <field name="condition">name != "" and original_image != ""</field> 
      <field name="signal">pending</field> 
     </record> 
     <record model="workflow.transition" id="product_images.wkf_transition_pending_to_draft"> 
      <field name="act_from" ref="product_images.wkf_activity_pending" /> 
      <field name="act_to" ref="product_images.wkf_activity_draft" /> 
      <field name="signal">draft</field> 
     </record> 
     <record model="workflow.transition" id="product_images.wkf_transition_pending_to_approved"> 
      <field name="act_from" ref="product_images.wkf_activity_pending" /> 
      <field name="act_to" ref="product_images.wkf_activity_approved" /> 
      <field name="signal">approve</field> 
     </record> 
     <record model="workflow.transition" id="product_images.wkf_transition_pending_to_rejected"> 
      <field name="act_from" ref="product_images.wkf_activity_pending" /> 
      <field name="act_to" ref="product_images.wkf_activity_rejected" /> 
      <field name="signal">reject</field> 
     </record> 
    </data> 
</odoo> 

今や最も盛り上がった部分!私は、ワークフローの状態と現在のアクティブな状態を示すステータスバーを切り替えるためのボタンがあるフォームが必要です。これは私が試したものです:

<record model="ir.ui.view" id="product_images.form"> 
     <field name="name">Product Image</field> 
     <field name="model">product_images.product_image</field> 
     <field name="arch" type="xml"> 
      <form> 
       <header> 
        <!-- 
        <button name="draft" 
          type="workflow" 
          string="Set to draft" 
          attrs="{'invisible': [('state_id.slug','not in',['pending'])]}" 
        /> 
        <button name="pending" 
          type="workflow" 
          string="Request for approval" 
          attrs="{'invisible': [('state_id.slug','not in',['draft'])]}" 
        /> 
        <button name="approve" 
          type="workflow" 
          string="Approve" 
          attrs="{'invisible': [('state_id.slug','not in',['pending'])]}" 
          class="oe_highlight" 
        /> 
        <button name="reject" 
          type="workflow" 
          string="Reject" 
          attrs="{'invisible': [('state_id.slug','not in',['pending'])]}" 
          class="oe_highlight" 
        /> 
        --> 
        <field name="state_id" widget="statusbar" /> 
       </header> 

       <sheet> 
        <group> 
         <field name="product_id" /> 
         <field name="name" string="Alternative text" /> 
         <field name="original_image" widget="image" class="oe_avatar" /> 
         <field name="state_id" /> 
        </group> 
       </sheet> 
      </form> 
     </field> 
    </record> 

私が得た問題:

  1. ステータスバーが表示されますが、現在の発行状況が活性化されていません。
  2. 私はボタンのコメントを解除した場合、彼らは無効なドメインに関するエラーをスロー:

Uncaught Error: Unknown field state_id.slug in domain [["state_id.slug","not in",["pending"]]]

私は何をしないのですか?

答えて

1

ドメイン属性では、左側に親フィールドを使用できません。あなたの場合、関連するフィールドを追加する必要があります。例えば

はあなたのビューファイル<button>

<field name="slug" invisible="1"/> 

今すぐコメント解除コードでをSTATE_ID後

スラグフィールドを入れてください。

その後、Odooサーバーを再起動し、カスタムモジュールをアップグレードします。

+1

ありがとうございました。出来た。私はちょうどこのようなボタンを変更しなければならなかった:

+0

はい。 * button attrs *の* state_id.slug *は必要ありません。 –

関連する問題