Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
3573 Tampilan
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
Buang

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

Jawaban Terbai

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
Buang
Penulis

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

Penulis

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

Post Terkait Replies Tampilan Aktivitas
name_get Diselesaikan
2
Jul 24
9867
2
Apr 23
2810
2
Feb 25
40497
2
Nov 22
2873
1
Feb 22
7909