When click on save button gives me odoo server error shown in screenshot
and at backed following error display.
2019-12-14 12:36:25,426 4067 ERROR work_span odoo.sql_db: bad query:
INSERT INTO "survey_page" ("id", "create_uid", "create_date",
"write_uid", "write_date", "create_id_survey", "sequence", "title")
VALUES (nextval('survey_page_id_seq'), 1, (now() at time zone 'UTC'),
1, (now() at time zone 'UTC'), 1, 10, 'test1') RETURNING id ERROR:
null value in column "survey_id" violates not-null constraint DETAIL:
Failing row contains (5, 1, test1, null, 10, null, 1, 2019-12-14
12:36:25.421912, 1, 2019-12-14 12:36:25.421912).
UPDATE
Description: I am trying to display survey title, survey page, survey question in one form for that I have create my custom model. Custom model inherit survey.survey,survey.page,survey.question and also contain two one2many field.
Following is my code:
py file
class SurveyCreate(models.Model):
_name = 'create.survey'
_inherit = ['survey.survey','survey.page','survey.question']
pages_id = fields.One2many('survey.page','create_id_survey','Pages')
questions_survey = fields.One2many('survey.question','create_id_survey','Questions')
survey_id = fields.Many2one('survey.survey', string='Survey',required=False)
page_id = fields.Many2one('survey.page', string='Survey page', required=False)
Xml file
<sheet>
<group>
<field name="title"/>
</group>
<group>
<field name="pages_id" mode="tree">
<tree editable="bottom">
<control>
<create string="Add page"/>
</control>
<field name="title"/>
<field name="questions_id" widget="many2many_tags" context="{'tree_view_ref':'survey_inherit.survey_create_form','default_page_id':active_id}"/>
</tree>
</field>
</group>
<group>
<field name="questions_survey" mode='tree'>
<tree name="questions_tree" editable="bottom">
<control>
<create string="Add Question"/>
</control>
<field name="question"/>
<field name="type"/>
</tree>
</field>
</group>
<group>
<group>
<field name="question"/>
</group>
<group>
<field name="type"/>
</group>
</group>
</sheet>
</form>
as per #Atul suggestion make changes but same error occur
Following screenshot for 1.Form View 2.Error after click on save button
It seems you have created a custom survey action model. and trying to use survey.page as one2many or many2many field on it.
when you add the page and try to save the record it is preventing because in default survey module survey_id field is mandatory. you can have two options to resolve this issue.
inherit the survey.page and Overwrite the field and make it non-required.
survey_id = fields.Many2one('survey.survey', string='Survey', required=False)
Populate the value of survey_id by default (you can use ir.config_parameter)
hope this helps!
Edit: 19th December 2019
You do not need to inherit the create.survey from any model if you do not required to change anything on the default survey mode.
class SurveyCreate(models.Model):
_name = 'create.survey'
_inherit = ['survey.survey','survey.page','survey.question']
Remove the below line from your class.
_inherit = ['survey.survey','survey.page','survey.question']
Instead create a new class for survey.page and overwrite the field like
class SurveyPage(models.Model):
_name = 'survey.page'
survey_id = fields.Many2one('survey.survey', string='Survey', required=False)
Looks like you've created a menu/action for a model which is only used in One2many fields, so the form view of that model is not showing the relation's inverse field (survey_id). In One2many fields there is no need to show this field, because Odoo is doing some black magic for them.
So the best way IMO is to create your own form view for that model. You also have to specify this form view as default on your menu action.
I am trying to get some values from (hr.payslip) model. Before that I need to add one more option in Action (dropdown list) where you can delete or export selected payslip. So when I select a payslip from treeView (checkbox in the image below) that new option should show up a wizard showing a table One2many having the selected payslip so I can Print or do some other action.
This is the scenario and i did not start any coding to do that.
I am new to odoo. I hope you can help me with some example.
you have to create new action and new object also
create new object
class NewObject(models.TransientModel):
_name = 'new.object'
_description = 'Description of new object'
#api.multi
def generate_report(self):
payslip_ids = self._.get('active_ids',[])
#payslip_ids this will be your selected payslip ids in list view.
<act_window
name="Your Action string"
res_model="new.object"
src_model="hr.payslip"
view_mode="form"
view_type="form"
target="new"
multi="True"
key2="client_action_multi"
id="id_of_act_window"
view_id="view of new object"
/>
then create view for new object
<record id="id of new view" model="ir.ui.view">
<field name="name">Name of view</field>
<field name="model">model of new view</field>
<field name="arch" type="xml">
<form string="">
<button name="generate_report" string="Generate Report
type="object" class="oe_highlight" />
</form>
</field>
</record>
and here you can add your code you want like.
I added a new field in account.config.settings model. It displays the new field in settings page and can enter the value. But when i reopen the page the value is not there. I know the Transient model won't store values for long.
But rest of the values still there, how can i achieve this?
Below is my code.
*.py
class AccountSettings(models.TransientModel):
_inherit='account.config.settings'
#api.one
def _get_header(self):
header = fields.Char('Header')
*.xml
<record id="view_account_config_settings_inherit" model="ir.ui.view">
<field name="name">view.account.config.settings.inherit.form</field>
<field name="model">account.config.settings</field>
<field name="inherit_id" ref="account.view_account_config_settings"/>
<field name="arch" type="xml">
<xpath expr="//group[#name='accounting']" position="after">
<group string="Reports" name="reports">
<field name="header" class="oe_inline"/>
</group>
</xpath>
</field>
</record>
In account.config.settings Model you can save your value by using this :
class AccountSettings(models.TransientModel):
_inherit='account.config.settings'
header = fields.Char('Header')
#api.multi
def set_header_defaults(self):
return self.env['ir.values'].sudo().set_default(
'account.config.settings', 'header', self.header)
Try this code:
class AccountSettings(models.TransientModel):
_inherit='account.config.settings'
#api.one
def _get_header(self):
header = fields.Char('Header',config_parameter='header.configuration')
you can name the attribute config_parameter anything you want. And it will be used to get the value of header from other models.
example:
test = self.env['ir.config_parameter'].get_param('**header.configuration**', '').strip()
test will return the temporary stored value in account.config.settings.
I've been trying to modify project issue object.
and When I click Assign to field, It shows a list of users with dropdown.
But I'd like to change its order to DESC.
Is there any thing I can do in View?
here is my code below
<record id="project_issue_custom_form" model="ir.ui.view">
<field name="inherit_id" ref="project_issue.project_issue_form_view"/>
<field name="model">project.issue</field>
<field name="arch" type="xml">
<field name="user_id" position="attributes">
<attribute name="default_order">sequence desc</attribute>
</field>
</field>
</record>
Also I tried in controller
class Project_issue(models.Model):
_inherit = "project.issue"
_order = "user_id desc"
But It still doesn't affected.
The tag default_order can only be used for lists and kanban views. But you want to change the order of the content of a many2one field (user_id on project.issue).
Your second approach has potential. But it is the wrong model:
class ResUsers(models.Model):
_inherit = "res.users"
_order = "name desc" # or id
Lets assume the following model
class visit(osv.Model):
_name = "visit"
_order = "date desc"
_rec_name = "date"
_columns = {
'date': fields.datetime('Date/Time', required=True),
'res_partner_id': fields.many2one('res.partner', 'Client', required=True),
}
And we have the following view:
<record id="visit_form_view" model="ir.ui.view">
<field name="name">visit.form.view</field>
<field name="view_type">form</field>
<field name="model">visit</field>
<field name="arch" type="xml">
<form string="Visit">
<field name="date" />
<field name="res_partner_id" />
</form>
</field>
</record>
I have extended the res.partner to display a list of visits within a notebook page. When I Add an Item to the visits page within the customer, how do I set the default value of the res_partner_id combobox to the current customer?
After reading your question and comment, I would suggest you to use one2many relation between two objects and keep one2many list view inside partner, from where one can create the record , does not need to select the partner and record is created only for that partner.
Cheers,
Parthiv
Google OpenERP _defaults (a dictionary) and default_get (a method).