Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

many2many update does not work!

By
Tarif Ezaz
on 8/21/14, 5:56 PM 1,797 views

I have the following relationships between two objects:

class nsalesorder(osv.osv):
    _description = 'Sales Order'
    _name = 'nsales.order'

    _columns = {

           #other attributes

          'report_id': fields.many2many('nsales.report' , 'Report ID')

     

class nreport(osv.osv):
    _description = 'Report'
    _name = 'nsales.report'

    _columns = {

          order_id': fields.many2many('nsales.order', 'order_report')
    

So, report and order has a many2many relation. But when I try to create a report object with the following code:

def create(self, cr, uid, vals, context=None):
        sales_order_object = self.pool.get('nsales.order')
        ids = sales_order_object.search(cr, uid, [ ['order_date','>=', vals['start_date'] ], ['order_date','<=',vals['end_date'] ] ], offset=0, order=None, context=None)

        vals['order_id'] = (0, 0, ids )
        ret = super(nreport, self).create(cr, uid, vals, context=context )
    

The relation order_report remains empty. But the code does not give any error and a new entry is created in the nsalse_report table. 

How can I change the code so that the relationship between these two objects is created? I am stuck with this problem for a while. Some help will be highly appreciated. 

Regards

Tarif

0
klacus
On 8/21/14, 8:53 PM

Hi.

Yes, because your ref_table is empty.

Can you try to redifine your many2many:

according to this:

fields.many2many('that object name', 'sql relation table name', 'this object id', 'that object id', 'Field Lable')

 

so in this case:

 'report_id': fields.many2many('nsales.report' , 'rep_table_name','nsales_order_id','nsales_report_id')

or

 'order_id': fields.many2many('nsales.order', 'rep_table_name','nsales_report_id','nsales_order_id','Some Label')

you can see at account.py

        'financial_report_ids': fields.many2many('account.financial.report', 'account_account_financial_report', 'account_id', 'report_line_id', 'Financial Reports'),

and the pair in account_financial_report.py

'account_ids': fields.many2many('account.account', 'account_account_financial_report', 'report_line_id', 'account_id', 'Accounts'),

Hope this helps.

B.R.

L.

Thanks a lot klacus for your kind and precise reply. I'll try it right and will let you know the updates. Regards

Tarif Ezaz
on 8/22/14, 12:06 PM

I have tried exactly what you've said. I updated the following attributes like this: 'report_id': fields.many2many('nsales.report' , 'order_report','nsales_order_id','nsales_report_id','Monthly Order') 'order_id': fields.many2many('nsales.order', 'order_report','nsales_report_id','nsales_order_id','Monthly Order') And my insert code is: sales_order_object = self.pool.get('nsales.order') ids = sales_order_object.search(cr, uid, [ ['order_date','>=', vals['start_date'] ], ['order_date','

Tarif Ezaz
on 8/22/14, 1:00 PM

Hi. Works?

klacus
on 8/22/14, 1:07 PM

Please ignore my comment here and see my above post :)

Tarif Ezaz
on 8/22/14, 1:07 PM

It's not working yet. I have updated the attributes like you've said. I have posted my code in my updated post :)

Tarif Ezaz
on 8/22/14, 1:11 PM

Thank you very much klacus for your relentless support. Sorry that I could not inform you earlier. I have been sick for all this week. Your solutions worked like a charm :D

Tarif Ezaz
on 8/28/14, 5:50 AM
0
Tarif Ezaz
On 8/22/14, 12:05 PM

Thanks a lot klacus for your kind and precise reply. I'll try it right and will let you know the updates.

Regards

Update:

I have updated the attributes like this:

'order_id': fields.many2many('nsales.order', 'order_report','nsales_report_id','nsales_order_id','Monthly Order')

and

 'report_id': fields.many2many('nsales.report' , 'order_report','nsales_order_id','nsales_report_id','Monthly Order')

My create code is:

sales_order_object = self.pool.get('nsales.order')
ids = sales_order_object.search(cr, uid, [ ['order_date','>=', vals['start_date'] ], ['order_date','<=',vals['end_date'] ] ], offset=0, order=None, context=None)
vals['order_id'] = (0, 0, ids )
ret = super(nreport, self).create(cr, uid, vals, context=context )
return ret

But the result is still the same. I can not create any entry in order_report table. Am I missing something?

 

 

Are you restarted the server and reinstall the modul?

klacus
on 8/22/14, 1:11 PM

yep, I've done it.

Tarif Ezaz
on 8/22/14, 1:12 PM

klacus, kindly check your inbox. :)

Tarif Ezaz
on 8/22/14, 1:24 PM
Hi.

Ok.
I will model this, I think I need some hour to understand. :-)

Tomorow I think I can answer to you.

B.R.
Laci

2014-08-22 19:24 keltezéssel, Tarif Ezaz írta:
<blockquote cite="mid:1408728241.405917882919312.995377474845259-openerp-60884-forum.post@accounts.odoo.com" type="cite">

klacus, kindly check your inbox. :)

--
Tarif Ezaz Sent by OpenERP S.A. using Odoo. about Forum Post False
klacus
on 8/22/14, 1:30 PM
Thanks man. Tomorrow will be great. I can't thank you more for what you've already done for me. Looking forward to your answer. Meanwhile, if I find anything, I'll let you know.

Regards
Tarif


On Fri, Aug 22, 2014 at 11:30 PM, <kozmalg@gmail.com> wrote:
Hi.

Ok.
I will model this, I think I need some hour to understand. :-)

Tomorow I think I can answer to you.

B.R.
Laci

2014-08-22 19:24 keltezéssel, Tarif Ezaz írta:
<blockquote cite="mid:1408728241.405917882919312.995377474845259-openerp-60884-forum.post@accounts.odoo.com" type="cite">

klacus, kindly check your inbox. :)

--
Tarif Ezaz Sent by OpenERP S.A. using Odoo. about Forum Post False
--
klacus Sent by OpenERP S.A. using Odoo. about Forum Post False



--
Tarif Ezaz
on 8/22/14, 1:32 PM
Hi Tarif

Great!
B.R.
Laci
2014-08-22 19:32 keltezéssel, Tarif Ezaz írta:
<blockquote cite="mid:CAKnpPZRO55BFjhco-0m-t0Nv161wq9saAXkOAAe6keGaCzFe-Q@mail.gmail.com" type="cite">
Thanks man. Tomorrow will be great. I can't thank you more for what you've already done for me. Looking forward to your answer. Meanwhile, if I find anything, I'll let you know.

Regards
Tarif


On Fri, Aug 22, 2014 at 11:30 PM, <kozmalg@gmail.com> wrote:
Hi.

Ok.
I will model this, I think I need some hour to understand. :-)

Tomorow I think I can answer to you.

B.R.
Laci

2014-08-22 19:24 keltezéssel, Tarif Ezaz írta:
<blockquote cite="mid:1408728241.405917882919312.995377474845259-openerp-60884-forum.post@accounts.odoo.com" type="cite">

klacus, kindly check your inbox. :)

--
Tarif Ezaz Sent by OpenERP S.A. using Odoo. about Forum Post False
--
klacus Sent by OpenERP S.A. using Odoo. about Forum Post False



--
--
Tarif Ezaz Sent by OpenERP S.A. using Odoo. about Forum Post False
klacus
on 8/22/14, 1:35 PM
Hi.

It works! Without any change of many2many definition. :-) I am happy :-)
I create a simplefied sample modul to better understanding.
Just try to install and analyse it pls.

I attach to you a very simplified content, please try rebuild your job according this.

Usage:
Create a Order inside Order_122
Create a report_122 1-2-3 pcs

Edit the order inside Order_122 >> add the realtion with report.

Please be note first try it by hand, if you want to automatise this procedure, you can do it with sql. (dirty but efficient (insert into Monthly_order....))

If you have any question, just send a a mail.

B.R.
Laci


2014-08-22 19:32 keltezéssel, Tarif Ezaz írta:
<blockquote cite="mid:CAKnpPZRO55BFjhco-0m-t0Nv161wq9saAXkOAAe6keGaCzFe-Q@mail.gmail.com" type="cite">
Thanks man. Tomorrow will be great. I can't thank you more for what you've already done for me. Looking forward to your answer. Meanwhile, if I find anything, I'll let you know.

Regards
Tarif


On Fri, Aug 22, 2014 at 11:30 PM, <kozmalg@gmail.com> wrote:
Hi.

Ok.
I will model this, I think I need some hour to understand. :-)

Tomorow I think I can answer to you.

B.R.
Laci

2014-08-22 19:24 keltezéssel, Tarif Ezaz írta:
<blockquote cite="mid:1408728241.405917882919312.995377474845259-openerp-60884-forum.post@accounts.odoo.com" type="cite">

klacus, kindly check your inbox. :)

--
Tarif Ezaz Sent by OpenERP S.A. using Odoo. about Forum Post False
--
klacus Sent by OpenERP S.A. using Odoo. about Forum Post False



--
--
Tarif Ezaz Sent by OpenERP S.A. using Odoo. about Forum Post False
klacus
on 8/22/14, 11:48 PM
Hi Tarif.

Just remove some depends from openerp.py because I think I forget to remove it..
Sorry :-)

I modified it.

B.R.
L.

2014-08-22 19:32 keltezéssel, Tarif Ezaz írta:
<blockquote cite="mid:CAKnpPZRO55BFjhco-0m-t0Nv161wq9saAXkOAAe6keGaCzFe-Q@mail.gmail.com" type="cite">
Thanks man. Tomorrow will be great. I can't thank you more for what you've already done for me. Looking forward to your answer. Meanwhile, if I find anything, I'll let you know.

Regards
Tarif


On Fri, Aug 22, 2014 at 11:30 PM, <kozmalg@gmail.com> wrote:
Hi.

Ok.
I will model this, I think I need some hour to understand. :-)

Tomorow I think I can answer to you.

B.R.
Laci

2014-08-22 19:24 keltezéssel, Tarif Ezaz írta:
<blockquote cite="mid:1408728241.405917882919312.995377474845259-openerp-60884-forum.post@accounts.odoo.com" type="cite">

klacus, kindly check your inbox. :)

--
Tarif Ezaz Sent by OpenERP S.A. using Odoo. about Forum Post False
--
klacus Sent by OpenERP S.A. using Odoo. about Forum Post False



--
--
Tarif Ezaz Sent by OpenERP S.A. using Odoo. about Forum Post False
klacus
on 8/23/14, 12:02 AM
Hey thanks!

Could you please tell me where did made changes? I couldn't figure it out it yet. :(

Tarif


On Sat, Aug 23, 2014 at 10:02 AM, <kozmalg@gmail.com> wrote:
Hi Tarif.

Just remove some depends from openerp.py because I think I forget to remove it..
Sorry :-)

I modified it.

B.R.
L.


2014-08-22 19:32 keltezéssel, Tarif Ezaz írta:
<blockquote cite="mid:CAKnpPZRO55BFjhco-0m-t0Nv161wq9saAXkOAAe6keGaCzFe-Q@mail.gmail.com" type="cite">
Thanks man. Tomorrow will be great. I can't thank you more for what you've already done for me. Looking forward to your answer. Meanwhile, if I find anything, I'll let you know.

Regards
Tarif


On Fri, Aug 22, 2014 at 11:30 PM, <kozmalg@gmail.com> wrote:
Hi.

Ok.
I will model this, I think I need some hour to understand. :-)

Tomorow I think I can answer to you.

B.R.
Laci

2014-08-22 19:24 keltezéssel, Tarif Ezaz írta:
<blockquote cite="mid:1408728241.405917882919312.995377474845259-openerp-60884-forum.post@accounts.odoo.com" type="cite">

klacus, kindly check your inbox. :)

--
Tarif Ezaz Sent by OpenERP S.A. using Odoo. about Forum Post False
--
klacus Sent by OpenERP S.A. using Odoo. about Forum Post False


--
Tarif Ezaz Sent by OpenERP S.A. using Odoo. about Forum Post False
--
klacus Sent by OpenERP S.A. using Odoo. about Forum Post False



--
Tarif Ezaz
on 8/23/14, 1:27 AM
Great! I'll try it and will let you know asap.
Tarif Ezaz
on 8/23/14, 1:28 AM
OK!

2014-08-23 07:29 keltezéssel, Tarif Ezaz írta:
<blockquote cite="mid:CAKnpPZROo9Nq91DUj2C99v_teWJrLBd1nAY+L0xQsog6q7x86Q@mail.gmail.com" type="cite">
Great! I'll try it and will let you know asap.
--
Tarif Ezaz Sent by OpenERP S.A. using Odoo. about Forum Post False
klacus
on 8/23/14, 1:39 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 8/21/14, 5:56 PM
Seen: 1797 times
Last updated: 3/16/15, 8:10 AM