The states of a model for the Workflows in Odoo - odoo-10

I am trying to implement Odoo publishing workflows for my custom model 'product_images.product_image'.
My models look like this:
# 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']])
Then I have some data records for the publishing statuses:
<!-- 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>
I also have some records to create a workflow which allows to switch between the publishing statuses:
<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>
And now the tickiest part! I need a form with the buttons to switch between workflow states and a status bar showing the currently active status. This is what I tried:
<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>
The problems I got:
The status bar is shown, but the current publishing status is not activated.
If I uncomment the buttons, they throw an error about invalid domain:
Uncaught Error: Unknown field state_id.slug in domain
[["state_id.slug","not in",["pending"]]]
What am I missing?

In domain attribute, we can not use parent field in left hand side. In your case, we need to add related field.
For example:
class ProductImage(models.Model):
_name = 'product_images.product_image'
slug = fields.Char(related='state_id.slug', string='Slug', store=True)
Put slug field after state_id in your view file
<field name="slug" invisible="1"/>
Now uncomment <button> codes.
Afterwards, restart Odoo server and upgrade your custom module.

Related

AssertionError: Element odoo has extra content: record, line 4

I'm trying to add multi field to timesheet module to work as a tasks manage app i did inheritance to account.analytic.line the problem is in the view i got that error "AssertionError: Element odoo has extra content: record, line 4"
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="todo_timesheet_line_tree" model="ir.ui.view">
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_tree"/>
<field name="model">account.analytic.line</field>
<field name="arch" type="xml"/>
<field name="task_id" position="after">
<field name="priority"/>
</field>
<field name="company_id" groups="base.group_multi_company" position="before">
<field name="gov_department"/>
<field name="priority"/>
<field name="date_deadline"/>
</field>
</record>
</odoo>
from odoo import models, fields, api
class TodoTask(models.Model):
_inherit = 'account.analytic.line'
startdate=fields.Date('start Date', required=True, index=True, default=fields.Date.context_today)
date_deadline=fields.Date('Deadline', required=True, index=True, default=fields.Date.context_today)
priority = fields.Selection(selection=[('1', 'فوري'), ('2','هام جدا' ),('3','اقل اهمية')])
is_done = fields.Boolean ('Done?')
gov_department = fields.Many2one('govauthority','الجهة الحكومية')
class govauthority(models.Model):
govname = fields.Char('GOV_Department', size=25, required=True)
The error is in this line
<field name="arch" type="xml" />
You closed the tag while you really should not. Within this tag the actual XML body should be.
<record id="todo_timesheet_line_tree" model="ir.ui.view">
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_tree" />
<field name="model">account.analytic.line</field>
<field name="arch" type="xml">
<field name="task_id" position="after">
<field name="priority" />
</field>
<field name="company_id" groups="base.group_multi_company" position="before">
<field name="gov_department" />
<field name="priority" />
<field name="date_deadline" />
</field>
</field>
</record>

Odoo - Filter child records in parent class

I am using Odoo 10-e. I am working on a sample module.
I have 5 models (customer, product, order, order details, movement)
Customer :
class Customer(models.Model):
_name ="amgl.customer"
…… all other fields related to customer
product_ids = fields.Many2many('amgl.products', string='Products')
Products :
class Products(models.Model):
_name ="amgl.products"
…… all other fields related to product
customer_ids = fields.Many2many('amgl.customer', string='Customers')
Order :
class Order(models.Model):
_name ="amgl.order"
order_line = fields.One2many('amgl.order_line', 'order_id', string='Order Lines')
…… all other fields related to Order
Order Details :
class OrderLine(models.Model):
_name = 'amgl.order_line'
order_id = fields.Many2one('amgl.order', string='Orders')
products = fields.Many2one('amgl.products', string="Products")
…… all other fields related to order details
Movement
class Movement(models.Model):
_name = 'amgl.metal_movement'
customer = fields.Many2one("amgl.customer", string="Customer", required=True)
order_lines = fields.One2many('amgl.order_line','metal_movement_id')
…… all other fields related to movement
What i am trying to do is, i am creating a movement form in which user will select a customer from customer drop down first then user will add order_lines and in that he will be able to add products i want to filter products which are associated with above selected customer . How can i do that ? I have been trying since last month.
Movement View
<odoo>
<data>
<record id="action_metal_movement" model="ir.actions.act_window">
<field name="name">Metal Movement Request</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">metal.movement</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to create
</p><p>
<!-- More details about what a user can do with this object will be OK -->
</p>
</field>
</record>
<record id="form_metal_movement" model="ir.ui.view">
<field name="name">Metal Movement Request </field>
<field name="model">metal.movement</field>
<field name="arch" type="xml">
<form string="Metal Movement">
<sheet>
<group>
<group string="Metal Movement Request">
<field name="date_create" string="Date Created"/>
<field name="reference"/>
<field name="metal_movement_type"/>
<field name="first_approve"/>
<field name="second_approve" domain="[('id', '!=', first_approve)]"/>
<field name="customer"/>
<field name="sepcial_instruction" widget="html"/>
</group>
<group string="Metal Movement From">
<group colspan="6">
<field name="custodian"/>
<field name="mmf_name"/>
<field name="mmf_account_number"/>
<field name="mmf_account_type"/>
</group>
<group string="Metal Movement To" colspan="6">
<field name="mmt_name"/>
<field name="mmt_address" attrs="{'invisible':[('metal_movement_type', '=', 'IT')]}"/>
<field name="mmt_account_number" />
<field name="mmt_company" attrs="{'invisible':[('metal_movement_type','not in',('AC','IPPU','IT'))]}"/>
<field name="pickup_date" string="Pick up Datetime" attrs="{'invisible':[('metal_movement_type','not in',('AC','IPPU'))]}"/>
</group>
</group>
<group string="Metals To Be Moved" colspan="12">
<field name="order_lines">
<tree editable="bottom">
<field name="quantity" string="Quantity"/>
<field name="products" domain="[('customer_ids','in', parent.customer)]" string="Product Name"/>
<field name="weight" string="Weight"/>
<field name="total_weight" string="Total Weight"/>
</tree>
</field>
</group>
</group>
</sheet>
</form>
</field>
</record>
</data>
</odoo>
Thank you for updation of question.
First add customer in product field context.
<field name="order_lines">
<tree editable="bottom">
<field name="quantity" string="Quantity"/>
<field name="products" context="{'customer_id':parent.customer}" string="Product Name"/>
<field name="weight" string="Weight"/>
<field name="total_weight" string="Total Weight"/>
</tree>
</field>
Then in product's model write it's name_get method like this.
#api.multi
def name_get(self):
if self.env.context('customer_id',False):
customer = self.env['amgl.customer'].browse(self.env.context('customer_id',False))
for product in customer.product_ids:
res.append((product.id,product.name))
else:
res=super(product_product,self).name_get()
return res
Thats it.

Odoo 8 - Calendar View Error

Get an error: Odoo Warning - Insufficient fields for Calendar View! and the calendar, of course,never shows up.
I'm missing something but don't know what;
I have this view fragment:
<record model="ir.actions.act_window" id="action_soft_apps_event">
<field name="name">Applications</field>
<field name="res_model">soft.app</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form,calendar,graph</field>
<field name="arch" type="xml">
<calendar string="App Releases" color="dev_id" date_start="release" date_delay="1">
<field name="name"/>
<field name="desc"/>
<field name="downloads"/>
<field name="valid"/>
</calendar>
</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Register a new App</p>
</field>
</record>
And the model is the following:
class soft_app(osv.osv):
"""Apps"""
_name = 'soft.app'
_columns = {
'name': fields.char('Name', size=32, required=True, help='This is the name of the application'),
'desc': fields.text('Description', help='A brief description of the application'),
'dev_id': fields.many2one('soft.dev','Developer',required=True, help='The app\'s developer'),
'release': fields.datetime('Release Date', help='The date that the app was released'),
'downloads': fields.integer('Download Count', help='Total amount of downloads'),
'user_ids': fields.many2many('soft.user','soft_user_app_rel','app_id','user_id','Users Downloaded', help='Users that have downloaded the app'),
'os_ids': fields.many2many('soft.os','soft_os_app_rel','app_id','os_id','Operating Systems', help='Operating systems survey data'),
'valid': fields.boolean('Is Valid', help='Checks if the app is validated')
}
soft_app()
I think you have to create separate calendar view and action
Like:
Calendar view
<record id="view_invoice_line_calendar" model="ir.ui.view">
<field name="name">account.invoice.calendar</field>
<field name="model">account.invoice</field>
<field name="arch" type="xml">
<calendar string="Invoices" color="journal_id" date_start="date_invoice">
<field name="partner_id"/>
<field name="amount_total"/>
</calendar>
</field>
</record>
Action
<record id="action_invoice_tree" model="ir.actions.act_window">
<field name="name">Invoices</field>
<field name="res_model">account.invoice</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form,calendar,graph</field>
<field name="view_id" ref="invoice_tree"/>
<field name="context">{'type':'out_invoice'}</field>
<field name="search_view_id" ref="view_account_invoice_filter"/>
</record>

Odoo 9 add column to grid view

I'm create simple module with 4 fields (name,date,user,description).Below is my .xml file.
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_my_report_form" model="ir.ui.view">
<field name="name">penalty.form</field>
<field name="model">my.report</field>
<field eval="2" name="priority"/>
<field name="arch" type="xml">
<form string="Project">
<sheet string="My report">
<group>
<div class="oe_title">
<h1 class="o_row">
<field name="name" placeholder="Name..." />
</h1>
</div>
</group>
<group>
<field name="user" placeholder="User..."/>
</group>
<group>
<field name="date" placeholder="Date..."/>
</group>
<notebook>
<page name="description_page" string="Description">
<field name="description"/>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="action_my_report_form">
<field name="name">Add new</field>
<field name="res_model">my.report</field>
</record>
<menuitem name="MY report" id="menu_penalty" action="action_my_izvjestaj_form" sequence="1"/>
</data>
</openerp>
When open from menu in grid view visble is only name.
https://postimg.org/image/ccms5aww3/
How add date and user fields?
You need to declare Tree view for that model.
<!-- Tree Views BEGIN-->
<record model="ir.ui.view" id="view_my_report_tree">
<field name="name">penalty.tree</field>
<field name="model">my.form</field>
<field name="arch" type="xml">
<tree string="Project">
<field name="name"/>
<field name="user"/>
<field name="date"/>
</tree>
</field>
</record>

I am getting AssertionError: Element openerp has extra content: data, line 2

I am trying to install a module, then I am getting below error.
AssertionError: Element openerp has extra content: data, line 2
What type of mistake I did for getting this error.
In which file I have to search for error rectify. I am using odoo9.
Files:
This is my xmlfile.xml
<data>
<record model="ir.ui.view" id="10">
<field name="name">model.name</field>
<field name="model">smp.model2</field>
<field name="arch" type="xml">
<form>
<sheet>
<group colspan="4">
<group colspan="2" cal="2">
<field name="name"/>
<field name="active"/>
</group>
<group colspan="2" cal="2">
<field name="age"/>
<field name="sal"/>
</group>
<group colspan="2" cal="2">
<field name="adharid"/>
<field name="cell"/>
</group>
<notebook colspan="4">
<page string="extrainfo"><field name="extrainfo"/></page>
<page string="temporaryaddress"><field name="temporaryaddress"/></page>
<page string="perminantaddress"><field name="perminantaddress"/></page>
</notebook>
</group>
</sheet>
</form>
</field>
</record>
<record model="ir.ui.view" id="20">
<field name="name">model.name</field>
<field name="model">smp.model2</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="active"/>
<field name="age"/>
<field name="sal"/>
<field name="adharid"/>
<field name="cell"/>
<field name="extrainfo"/>
<field name="temporaryaddress"/>
<field name="perminantaddress"/>
</tree>
</field>
</record>
<record model ="ir.actions.act_window" id="action_smp_model2">
<field name="name">sampmodel</field>
<field name="res_model">smp.model2</field>
<field name="view_type">form</field>
<field name="viwe_mode">tree,form</field>
</record>
<menuitem id="smp_main_menu1" name="smp model2"/>
<menuitem id="subsmp_main_menu1" name="Sub sample model"
parent="smp_main_menu1"/>
<menuitem id="actsmp_main_menu" name="action smp model"
parent="subsmp_main_menu1" action="action_smp_model2"/>
</data>
</openerp>
This is my data.xml file
<data>
<record id='1' name="smp.model2">
<filed name="name">name1</filed>
<filed name="age">23</filed>
<filed name="cell">123456434</filed>
</record>
<record id='2' name="smp.model2">
<filed name="name">name1</filed>
<filed name="age">23</filed>
<filed name="cell">123456434</filed>
</record>
<record id='3' name="smp.model2">
<filed name="name">name1</filed>
<filed name="age">23</filed>
<filed name="cell">123456434</filed>
</record>
</data>
</openerp>
This is python_file.py
from openerp import models,fields
class model2(models.Model):
_name="smp.model2"
name=fields.Char(string="model name", requred=True, help="name of the
model")
active=fields.Boolean(String="Active")
age=fields.Integer(string="person age",help="age of person")
sal=fields.Integer(string="sal")
adharid=fields.Integer(string="Adhar Id")
cell=fields.Integer(string="phone number",requred=True)
extrainfo=fields.Text(string="Extra information")
temporaryaddress=fields.Text(string="Temporary address")
perminantaddress=fields.Text(string="perminant address")
This is __openerp__.py file
{
'name':'module12',
'description':'module12',
'author':'naveen',
'version':'9.0',
'depends':['base'],
'data':['xmlfile.xml','data.xml']
}
you have errors in a xml, example:
requred=True is required=True
<filed is <field

Resources