Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
3594 Visualizzazioni
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
Abbandona

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

Risposta migliore

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
Abbandona
Autore

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

Autore

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 correlati Risposte Visualizzazioni Attività
name_get Risolto
2
lug 24
9911
2
apr 23
2821
2
feb 25
40519
2
nov 22
2878
1
feb 22
7918