Odoo v11: How to pass a parameter to cron job - odoo-11

Here's my code snippet. I want to pass param1 to cron job.
How do I do that?
class MyTask(models.Model):
_name = "my.task"
#api.model
def cron_do_task(self, param1)
print(param1)
<record id="cron_do_task" forcecreate='True' model="ir.cron">
<field name="name">Do -Task</field>
<field eval="False" name="active"/>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">15</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field name="model_id" ref="model_my_task"/>
<field name="state">code</field>
<field name="code">model.cron_do_task(???)</field>
</record>
I believe args is no more available in v11

Related

Create a new tree view in Odoo13

I´m trying to create a new tree view for the invoices in Odoo 13
my code looks like this:
<odoo>
<record model="ir.ui.view" id="new_invoice_tree">
<field name="name">New Tree</field>
<field name="model">account.move</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree>
<field name="custom_field_1"/>
<field name="custom_field_2"/>
</tree>
</field>
</record>
<record id="my_module.new_tree_action_window" model="ir.actions.act_window">
<field name="name">New tree</field>
<field name="res_model">account.move</field>
<field name="view_mode">tree</field>
<field name="view_id" ref="new_invoice_tree"/>
<field name="type">ir.actions.act_window</field>
<field name="domain">[('type','=','out_invoice')]</field>
</record>
<menuitem name="Libro de ventas"
id="my_module.new_tree_menu"
parent="my_parent_menu"
action="my_module.new_tree_action_window"
sequence="1"/>
</odoo>
But when I try to open the menu appears this error:
Rastreo de error:
Error: Unknown field state in domain
at Class.compute (http://192.168.1.7:8070/web/content/317-6c3bb5c/web.assets_backend.js:322:55)
at evalModifier (http://192.168.1.7:8070/web/content/317-6c3bb5c/web.assets_backend.js:1197:91)
at Class._evalModifiers (http://192.168.1.7:8070/web/content/317-6c3bb5c/web.assets_backend.js:1200:44)
at Class._registerModifiers (http://192.168.1.7:8070/web/content/317-6c3bb5c/web.assets_backend.js:1401:101)
at Class._renderBodyCell (http://192.168.1.7:8070/web/content/317-6c3bb5c/web.assets_backend.js:2076:70)
at http://192.168.1.7:8070/web/content/317-6c3bb5c/web.assets_backend.js:2100:117
at Array.map (<anonymous>)
at Class._renderRow [as _super] (http://192.168.1.7:8070/web/content/317-6c3bb5c/web.assets_backend.js:2100:80)
at Class._renderRow (http://192.168.1.7:8070/web/content/317-6c3bb5c/web.assets_backend.js:2010:69)
at Class._renderRow (http://192.168.1.7:8070/web/content/312-75a923f/web.assets_common.js:3863:371)
I´m not sure how my domain should look like, what´s what I´m doing wrong?
The way to avoid this kind of error is by adding the "state" field with the attribute invisible as True, like this:
<odoo>
<record model="ir.ui.view" id="new_invoice_tree">
<field name="name">New Tree</field>
<field name="model">account.move</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree>
<field name="state" invisible="True"/>
<field name="custom_field_1"/>
<field name="custom_field_2"/>
</tree>
</field>
</record>
This error appears on databases that are working with the Enterprise version of Odoo.

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>

Hide lines in odoo treeview

I want to hide equipments that are not in an inventory. I've tried with
<record id="view_inventory_equipment_tree" model="ir.ui.view">
<field name="name">maintenance.equipment.tree</field>
<field name="model">maintenance.equipment</field>
<field name="domain">[('inventory_id','=',False)]</field>
<field name="arch" type="xml">
<tree string="Lot/Serial Number Inventory">
<field name="name"/>
<field name="serial_no"/>
<field name="category_id"/>
<field name="inventory_id"/>
<field name="cost"/>
</tree>
</field>
</record>
But that did not work, also there is no luck with
<field name="domain_force">[('inventory_id','=',False)]</field>
My model:
class MaintenanceEquipment(models.Model):
_name = 'maintenance.equipment'
_description = 'Equipment'
name = fields.Char('Equipment Name', required=True, translate=True)
inventory_id = fields.Many2one('maintenance.equipment.inventory', string='Equipment Inventory', track_visibility='onchange')
Put domain in action window record. Domain not work in directly with any view like tree or form view.

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>

The states of a model for the Workflows in Odoo

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.

Resources