Skip to Content
Menu
Dette spørgsmål er blevet anmeldt
1 Svar
86 Visninger

I’m working on a custom wizard and need some help defining a domain between two Many2one fields.

Here’s the setup:

class StockMoveRequestReportWizard(models.TransientModel): _name = "stock.move.request.report.wizard" _description = "Stock Move Request Report Wizard" source_store_id = fields.Many2one( 'res.store', string='Source Store', default=lambda self: self.env.user.store_ids, ) destination_store_id = fields.Many2one( 'res.store', string='Destination Store', )

The res.store model has a company_id field.

What I want to achieve is:

  • When a source_store_id is selected, the destination_store_id field should only show stores that belong to a different company than the selected source store.
Avatar
Kassér
Bedste svar

Hi,


Try the following,


destination_store_id = fields.Many2one(

    'res.store',

    string='Destination Store',

    domain="[('company_id', '!=', source_store_id.company_id)]"

)


Hope it helps

Avatar
Kassér
Forfatter

Thanks for the suggestion! I tried defining the field like this:

destination_store_id = fields.Many2one(
'res.store',
string='Destination Store',
domain="[('company_id', '!=', source_store_id.company_id)]"
)

But in my case, this is a wizard (TransientModel), and Odoo throws a validation error when loading the view:

Invalid composed field source_store_id.company_id in domain of field 'destination_store_id
It seems that XML domains in wizards cannot use composed fields like source_store_id.company_id.

Related Posts Besvarelser Visninger Aktivitet
2
nov. 25
9787
1
maj 25
3825
1
maj 24
3590
1
apr. 24
3031
2
apr. 24
4751