This question has been flagged
2 Replies
6962 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

Avatar
Discard
Best Answer

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.

Avatar
Discard
Author

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

Author

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','

Hi. Works?

Author

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

Author

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

Author

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

Author Best Answer

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?

 

 

Avatar
Discard

Are you restarted the server and reinstall the modul?

Author

yep, I've done it.

Author

klacus, kindly check your inbox. :)

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
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



--
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
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
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
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



--
Great! I'll try it and will let you know asap.
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