Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
3776 Переглядів
hi all,
class OrderItems(models.Model):
    _name = 'tests.orderitems'
    _description = "Tests Order Items"
    order_id = fields.Many2one('tests.myorders')
    categry_id = fields.Many2one('product.category', string="Category",
                                 domain="[['complete_name', 'not like', '%Brands%']]")
    items_id = fields.Many2one('tests.storeitems', string="Item",
                               domain="[['categs_id', '=', categry_id]]")
    # categ_name = fields.Char('Category Name', related='categry_id.complete_name', store=True)
    base_category = fields.Integer('Base Cat', related='categry_id.base_category')
    brand_id = fields.Many2one('product.category', string="Brand",
                               domain="[('base_category', '=', base_category),('complete_name', 'like', '%Brands /%')]")
    unit_id = fields.Many2one('tests.units', string="Unit")
    quantity = fields.Integer(string="Quantity", required=True, default=1)
    rates = fields.Float(string="Rate", default=0)
    size = fields.Char(string="Size")
both fields are based on model "product.category", and I want as below:
a) in Many2one field "categry_id" it should show the value of field "complete_name" -- its default
b) in Many2one field "brand_id" it should show the value of field "name" 
Sample:
complete_name contains  "  All / Electronics / Computer  "
for same entry name field contains "  Computer  "

regards
Аватар
Відмінити

Enhance the functionality of Many2One fields in Odoo with dynamic multi-field Search and Get capabilities. This app allows users to search and get records within Many2One fields using multiple fields. With a user-friendly configuration interface, you can easily specify the fields to be included in the search criteria, making it more efficient and flexible for finding records as well as displaying the records based on multiple fields instead of only name field.
https://apps.odoo.com/apps/modules/17.0/mh_dynamic_name_get_many2one

Найкраща відповідь

override name_get() method of supper (product.category) 
and change the behavior of the functional according to your need.

something like this :

@api.multi

def name_get(self):

    res = []
    for rec in self:
        if (active_reference_field == 'brand_id '):

            res.append((rec.id, "%s, %s" % (rec.name, rec.firstname or "")))
        else:
            res.append((rec.id, "%s" % rec.name))
    return res

Аватар
Відмінити
Автор

thanks a lot for help... will give you feedback :)

Автор

as my very little knowledge i have question, will you please help to get what is active_reference_field ? is it any kind of parameter ? how this will reference here ? pycharm is showing error as it is not recognizing it and i can't test it on my model.

i just give you code example of what should you do but you should apply the salutation in your end

Related Posts Відповіді Переглядів Дія
name_get Вирішено
2
лип. 24
10480
2
квіт. 23
2922
2
лют. 25
40783
2
лист. 22
2969
1
лют. 22
8006