Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
3641 Lượt xem
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
Ảnh đại diện
Huỷ bỏ

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

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
name_get Đã xử lý
2
thg 7 24
10038
2
thg 4 23
2864
2
thg 2 25
40623
2
thg 11 22
2906
1
thg 2 22
7933