Custom field

Asked by G Mangano on 2012-03-23

Hello
I have successfully created a custom field to add incoterms to the suppliers (res.partner)
What I need to do which I am struggling to achieve is to add/display this field to the purchase order form so that whenever I enter the supplier name the corresponding incoterms is added automatically with the option to alter it on the PO as occasionally the incoterm changes for the same supplier.
I hope it makes sense and would be grateful for a detailed instruction on how to as I am not familiar with module development though I tried quite many times.
I'm using version 6.1
many thanks

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Server (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
G Mangano
Solved:
2012-03-27
Last query:
2012-03-27
Last reply:
2012-03-24

Hello G Mangano,

You are half way down to the aim!

The way you create the field in supplier, do the same in Purchase Order.

Write an onchange on supplier of Purchase order to bring the value of the incoterms from chosen supplier.

Either way,if you want this Live effect, create a field of type fields.related.

Hope it helps.

Thanks,
Serpent Consulting Services.
http://www.serpentcs.com

G Mangano (mangofunky) said : #2

Thank you very much for your quick reply.
I tried to create the fields.related but still cannot get the incoterms showing up.
Let me summarise what I have done:
In Settings->Customization....
1. Created a many2one custom field (x_incoterms_id) in res_partner with object relation to stock.incoterms -
2. Added this field to the xml view and this works fine
3. Created a many2one custom field in purchase.order with object relation to res.partner (x_incoterms_id)
4. added the custom field to the PO view with the following <field name="x_incoterms_id" widget="selection"/> and what I get is the full selection list of all suppliers and not the incoterms.
I also tried to create a one2many field in PO relating to res.partner object and the x_incoterm field but still no luck.
Furthermore where should I put the on change rule? Did you mean to add it in the following tag
<field name="partner_id" on_change="onchange_partner_id(partner_id)" context="{'search_default_supplier':1,'default_supplier':1,'default_customer':0}" options="{&quot;quick_create&quot;: false}"/>
If yes how could I do this?
Sorry to be a pain
Thanks again

Hello G Mangano,

Your 3rd step should be:
3. Created a many2one custom field in purchase.order with object relation to stock.incoterms (x_incoterms_id)

And, You will get a selection list of all incoterms.

Additionally, to accomplish the auto selection of incoterm upon partner selection, you need :
<field name="partner_id" on_change="onchange_partner_id(partner_id)"

And this method should return the relevant field x_incoterms_id = x_incoterms_id of the partner chosen.

Thanks,
Serpent Consulting Services.
http://www.serpentcs.com

G Mangano (mangofunky) said : #4

Thank you very much for taking the time to look into this.
I changed step 3 and the list is now populated with incoterms correctly but the on_change behaviour is not working.
Where have i got it wrong?
The partner_id field has already got the suggested on_change.
I tried in several different ways but no joy.
Thanks once again

Hello G Mangano,

Good to know that you could manage to get the list populated now.

The next part is supposed to be done inside the module 'Purchase'.

Over there, def onchange_partner_id(self, cr, uid, ids, part): should return the x_incoterm_id.

We recommend you to do this in a separate module,so you can use this module anywhere, anytime.

Thanks.

G Mangano (mangofunky) said : #6

Great thank you very much that solved my problem

Anil (anilet) said : #7

Hi Everyone,
I am trying to get a similar scheme working.
I have successfully added few custom fields to project.project form view. One of it is a project no

I added many2one field "x_project_no" to project model, added the field to project.form view.
<field name="x_project_no" string="Project Number" select="1"/>
Everything works ok till now

Now I want the Project no to be automatically selected for each of the tasks in project.task view.
I have created a many2one field in project.task model, added the field to project.task.form
"<field name="x_project_no" select="1" on_change="onchange_project(x_project_no)"/>"

When I go to the tasks form, list populated by
Project name not project numbers.
Can anyone guide me how to do this?
Any help is much appreciated.
Thanks,
Anil

Anil,

Did you create the field as many2one ? with what model?

I see that you wrote on_change(), where did you write it?

Thanks.

Anil (anilet) said : #9

Thank you for replaying,
I did create the field as many2one, in project.project model
I went in to Config>Customizations>UI>View
and edited project.task.form
Added a field with
"<field name="x_project_no" select="1" on_change="onchange_project(x_project_no)"/>"
Hope this helps.
Anil

Anil,

Where did you add the onchange_project method?

Conceptually, you have to write a module to get the onchange effect.

Thanks.

Anil (anilet) said : #11

Hi,
I did not write a module, I did it in the browser using customisation menu
May be it's time to go through a tutorial to see if I can create a module myself.
Do you have any links/ suggestions on some tutorials in the subject.
I am currently trying to test the feasibility of using OpenERP to manage projects/tasks for our small manufacturing shop.
We have grown out of our current Excel setup.
Anyway thanks for your help
Anil

Anil,

You can go to http://goo.gl/n83aU.

I am sure this will help.

Thanks,
Serpent Consulting Services.
http://www/serpentcs.com