I am trying to use some fields of "Job Positions" in "Opportunities" and we can say it as a merger fields. but i am unable to do this task . i have no knowledge about Python language.
I have created a user defined fields and use it in opportunities by XML coding by developer options . I know that it is easy because user defined fields has "crm.lead" named module which is same in opportunities.
but now When i want to use this fields in "hr.job" then it give me error "fields not found" . i know that this fields is not in current module and it is part of "crm.lead" not "hr.job".
Is it possible to use one module fields in another module?
Yes you can do so. First you have to create an object for that and then browse the record and fetch the value of the field which you want.
For example create one method and then browse the crm.lead record:
crm_obj = self.pool.get('crm.lead')
crm_brw = crm_obj.browse(cr, uid, crm_rec_id, context=context)
print "my field value:: ", crm_brw.your_field
Here, "crm_rec_id" is the id of the record of crm.lead object
There are lots of examples given in addons.
yes you can it done by _inherits.
for eg.
hr_job in hr module .
class hr_job(osv.osv):
_name = "hr.job"
_description = "job position"
_columns = {
'name': fields.char('job name', size=64)
}
crm_lead in crm module.
class crm_lead(osv.osv):
_name = "crm.lead"
_inherits = {'hr.job': 'job_id'}
_description = "Lead/Opportunity"
_columns = {
'partner_id': fields.many2one('res.partner', 'Partner')
}
in xml file of crm create form view.
<record id="crm_lead_form" model="ir.ui.view">
<field name="name">crm.lead</field>
<field name="model">crm.lead</field>
<field name="arch" type="xml">
<form>
<field name="name"/> # job name from hr_job
<field name="partner_id"/> # partner_id from crm.lead
</form>
</field>
</record>
don't forget add dependency.
Related
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.
Given a custom model named 'Foo', I would like to add "tags" to it.
The code I am using:
class FooTag(models.Model):
_name = 'foo_tag'
_description = 'Foo Tag'
tag = fields.Char('Tag')
class Foo(models.Model):
_name = 'foo'
_description = 'Foo Model'
name = fields.Char('Name', required=True)
content = fields.Text('Foo Content')
tag_ids = fields.Many2many('foo_tag', string='Tags')
Here is the code for the view:
<record id="view_form_foo" model="ir.ui.view">
<field name="name">Foo Form</field>
<field name="model">foo</field>
<field name="arch" type="xml">
<form string="Foo">
<sheet>
<group>
<field name="name"/>
<field name="tag_ids" widget="many2many_tags"/>
<field name="content"/>
</group>
</sheet>
</form>
</field>
</record>
So far, so good.
But in the view I get the relationship (foo_tag,1) rather than the actual Tag name given. How could I display column 'Tag' of foo_tag instead of the relationship?
I have seen this post, but shows old API, any place where I can find an example for new API (Odoo 10)?
https://www.odoo.com/forum/help-1/question/many2many-tags-show-a-refrence-of-the-tag-not-the-name-24000
I got in another forum that:
Either 'tag' field is renamed to 'name' in foo_tag model.
_rec_name = 'tag' is added to foo_tag model.
This solves the issue.
In my custom module I use stock picking type to see the warehouse operations of the user.
class ResUsers(models.Model):
_inherit = 'res.users'
default_picking_type_ids = fields.Many2many(
'stock.picking.type', 'stock_picking_type_users_rel',
'user_id', 'picking_type_id', string='Warehouse Operations')
I added this in user form.
In my sexurity.xml file add
<record id="filter_user_stock_picking_type" model="ir.rule">
<field name="name">Filter Stock Picking Type</field>
<field name="model_id" search="[('model','=','stock.picking.type')]" model="ir.model"/>
<field name="groups" eval="[(4, ref('base.group_user'))]"/>
<field name="domain_force">[('id','in', [ s.id for s in user.default_picking_type_ids ])]</field>
</record>
so it is worked in when a user is created and assigns stock operation.
But when changed the stock operation to particular user, it will not affect.
How to resolve this issue??
I think, the problem is the Odoo Cache.
The old values are stored in the Cache for a long time and your change will not take any effect.
You can try it to clear the cache. It helped me to solve the similar problem.
class User(models.Model):
_inherit = 'res.users'
#api.multi
def write(self, vals):
ret = super(User, self).write(vals)
if 'default_picking_type_ids' in vals:
# clear default ir values when default_picking_type_ids changes
self.env['ir.values'].get_defaults_dict.clear_cache(self.env['ir.values'])
return ret
... In openerp7
I want my new state to show up in sale module ... But it is not appearing
Pls have a look at code below
In sale.py module I added state like:
class Sale_order(osv.Model):
_inherit = 'sale.order'
_columns = {
'state': fields.selection([
('draft', 'Draft Quotation'),
('my_new_state', 'My New State'),
('sent', 'Quotation Sent'),
('cancel', 'Cancelled'),
('waiting_date', 'Waiting Schedule'),
('progress', 'Sales Order'),
('manual', 'Sale to Invoice'),
('invoice_except', 'Invoice Exception'),
('done', 'Done'),
], 'Status', readonly=True, track_visibility='onchange',
help="Gives the status of the quotation or sales order. \nThe exception status is automatically set when a cancel operation occurs in the processing of a document linked to the sales order. \nThe 'Waiting Schedule' status is set when the invoice is confirmed but waiting for the scheduler to run on the order date.", select=True),
}
And in sale_view.xml, I added this piece of code..
<openerp>
<data>
<!-- Inherit the sale order model's form view and customize -->
<record id="sale_form_view" model="ir.ui.view">
<field name="name">sale.order.form.inherit</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<!-- Statusbar widget should also contain the new status -->
<field name="state" position="replace">
<field name="state" widget="statusbar" statusbar_visible="draft,my_new_state,sent,invoiced,done" statusbar_colors='{"invoice_except":"red","waiting_date":"blue"}'/>
</field>
</field>
</record>
</data>
But.... My new state is not appearing between draft quotation and quotation sent
Please guide
Why is this so
Thanks
First thing I would check is to make sure you are replacing the proper field in your view (if there are several instances of a field named "state" in the view you inherit, the wrong occurence could be replaced). Check the view by opening the 'Modify FormView' item in the developper tools/view.
If it is the wrong occurence you are replacing, you main need to change your view definition by using an xpath expression.
Second thing I would check, is make sure the sequence of your inherited view is smaller that the original view you are trying to replace/modify. You can check in 'Manage Views' item in the developper tools/view.
Third thing I would try is to rename your class from 'Sale_order' to 'sale_order' just to match the name of the original class your are trying to override.
Hope this helps.
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).