تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
3441 أدوات العرض

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
الصورة الرمزية
إهمال
أفضل إجابة
  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.


الصورة الرمزية
إهمال
أفضل إجابة

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

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
2
مايو 23
2053
2
نوفمبر 21
7835
1
مارس 17
8167
2
أبريل 15
10142
0
مارس 15
5127