Skip to Content
Menu
This question has been flagged

hi,
inheriting, how do i make the "partner_id" field in sale.order show only records that have a boolean field set to true but only if a boolean field in sale.order is true otherwise show all.

  1. for example if i have a boolean field on sale.order "field_boolean1" and if is true i want that partner_id show only the records that have "field_boolean2" on True
Avatar
Discard
Best Answer
  1. you can try this way:

  2. Define the boolean fields:

    • "field_boolean1" on the "sale.order" model
    • "field_boolean2" on the related "res.partner" model
  3. Inherit the "sale.order" model:

    • Create a new custom module or open an existing one where you want to make the changes.
    • Inherit the "sale.order" model using the appropriate Odoo/OpenERP method (e.g., models.Model or models.TransientModel).
  4. Override the "partner_id" field:

    • Inside your custom module, override the "partner_id" field to modify its domain filter.
    • Set the domain based on the conditions you specified:
      • If "field_boolean1" is true, show only the records in "partner_id" where "field_boolean2" is also true.
      • Otherwise, show all records in "partner_id".

example:

from odoo import models, fields

class SaleOrderInherit(models.Model):
_inherit = 'sale.order'

partner_id = fields.Many2one(
domain="[('field_boolean2', '=', True)]",
compute='_compute_partner_id',
store=True
)

@api.depends('field_boolean1', 'partner_id')
def _compute_partner_id(self):
for order in self:
if order.field_boolean1:
order.partner_id = order.partner_id.filtered(lambda r: r.field_boolean2)
else:
order.partner_id = order.partner_id

  1. Update your module:
    • Make sure to update your module dependencies and other required files (e.g., __manifest__.py) accordingly.
    • Restart the Odoo server to load the changes.


Avatar
Discard
Best Answer

Hi,

Seems you need to apply domain for the partner_id field in the sale.order model based on a field in the same model. Here you have two approaches, either you can return domain from an onchange function, which is deprecated in the latest version and not a stable method. Then using the web_domain_field module and using a computed field, it can be achieved.

See this video explaining the same:   https://www.youtube.com/watch?v=dq5Vtj_pwuI&t=311s

Thanks

Avatar
Discard
Related Posts Replies Views Activity
2
May 23
2033
2
Nov 21
7807
1
Mar 17
8141
2
Apr 15
10123
0
Mar 15
5108