Skip to Content
Menu
This question has been flagged
1 Reply
3405 Views

Hello Odoo community,

I'm making a custom module to manage access to building.

When granting access the user can select many partners. Once done, he can log departure for one or all of them.

For this purpose i created a model :

Access Model :

parter_ids = One2many(comodel_name="res.partner",inverse_name="Access_id") 
departed_partner_ids One2many(comodel_name="res.partner",inverse_name="Access_id")
@model
def get_log_departure_view(self) :
.....

So, the departure view is triggered by a button in the xml view, i tried something like : 

<field name="partner_ids" widget="many2many_tags" readonly="1"/>
<field name="departed_partner_ids" 
         widget="many2many_tags"
domain="[('id', 'in',partner_ids)]"
         options="{'no_create': True}"
 />

but this does not work, i have the following error :  not all arguments converted during string formatting

I think that's because partner_ids/partner_ids.id is substituted to something like "[ID,?,[ID1,ID2..]]"


Any idea, suggestion or solution for what I'm trying to achieve would be a great help :)

Thank you.

Avatar
Discard
Best Answer

The full code of your "Access Model" would be nice, because it is hard to understand what you are trying to achieve. It seems that both of your One2many fields point to the same inverse_name, thus meaning they will always show the same data? I have a feeling that a partner might have access to more than one building? If so you're probably better off using a Many2many relation. 

As for your domain, try changing it to this:

domain="[('id', 'in', partner_ids.ids)]"

Again, not sure why you need 2 One2many fields with the same inverse field, instead of focusing on the problem, try to explain your end goal, maybe then we can form a better solution for you.

Avatar
Discard
Author

Thank you for your time :)

Sorry, my mistake, actually it's not the same inverse_name, i just simplified the code for sake of clarity.

I extended res.partner to add the right inverse_names.

And no, a partner (or partners) must have only one access at once to a building. (so a m2o is more suitable for my case).

I already tried 'ids' attribute, but it does not work either : Error: AttributeError: object has no attribute 'ids'

i'll edit the question. thanks !

It is still weird that you want to put a domain on one of the One2many fields, they usually are not used with domains as the inverse field already specifies the relation and records will be filtered out based on that field.

Please post all of your code so I can help you

Author

Thanks again for your time.

Yes, i admit that the logic is somehow weird. I actually changed the 'departed_partner_ids' field to M2M relation. but i still have the same issue.

My py file contain more that 200 lines of code and related to 4 custom models (in addition of res.partner). it would be unnecessary and a pain to write it here !

the problem is as simple as i described it above.

reminder : what i'm trying to achieve is to filter a M2M domain field based on a O2M records.

ps: I can't update my question, i don't know why :/

Related Posts Replies Views Activity
6
Jun 16
3201
1
Jun 15
3142
2
Jun 15
2479
0
Sep 24
108
2
May 24
7389