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.
Related
Suppose we have a model named 'repertoire' with a field Many2many 'documents_id'
and i have a button in the many2many tree view ,in that button i want to get the id of the 'repertoire' i'm in
is there any solution for this
I found the answer ,we can pass a context to the many2many field ,for example :
<field name="app_ids" string="Apps" context="{'current_instance_id': id}">
<tree editable="false" create="false" delete="true">
<field name="name"/>
<button type="object" name="updating_module" icon="fa-refresh"/>
</tree>
</field>
on my function i can retrieve it :
def updating_module(self):
instance_id = self.env.context.get('current_instance_id')
Hello I need to add some information to the delete record confirmation dialog on Odoo 12, adding some information of how many dependent records will be deleted. Something like:
Are you sure you want to delete this record ?
Doing this you will lose N records.
Currently is defined on "addons/web/static/src/js/views/basic/basic_controller.js" on _deleteRecords method. But if I change it there it will be changed for all my modules.
I'm wondering if there is a method to overwrite this... Or my other idea is to hide the button and use a wizard to do it.
any idea?
By default odoo can do that from xml file but if you need dynamic message than
please create one transient model for wizard and this model have two fields which is your message field and your main form view id after that you simply override the method unlink and in method do your computations if you want confirmation in deletion then return from that condition like this:
return{
'type':'ir.actions.act_window',
'name':'Message',
'res_model':'your.wizard.model',
'view_type':'form',
'view_mode':'form',
'target':'new',
'context':{'thesis_obj':self.id,'text_message_field':'course Work completed'},
'res_id':value.id
}
After wizard opened you have your wizard's form view right?
in wizard form view if user click on OK button then call your original method from which you have to do it in first place.
Wizard View Reference:
<record id="wizard_message_form_view" model="ir.ui.view">
<field name="name">Approval Message</field>
<field name="model">your.wizard.model</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Message">
<separator string="Message" colspan="6"/>
<field name="text_message" colspan="4" nolabel="1" readonly="1" widget="html"/>
<newline/>
<separator colspan="6"/>
<footer>
<button name="btn_approve_oric" type="object" string="OK" class="oe_highlight"/>
<button special="cancel" string="No"/>
</footer>
</form>
</field>
Feel free to ask.
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 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.
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).