Skip to Content
Menu
This question has been flagged
1 Reply
2825 Views
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
Avatar
Discard

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

Best Answer

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

Avatar
Discard
Author

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

Author

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 Replies Views Activity
name_get Solved
2
Jul 24
7197
2
Apr 23
1976
2
Feb 25
38456
2
Nov 22
2086
1
Feb 22
7189