Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
2215 Lượt xem

im trying to get the id of the current model that i edit or created but i cant get it
below is my code

def _get_basic_product_information_purchase(self, product_or_template, pricelist, combination, **kwargs):
        basic_information = dict(
            **product_or_template.read(['description_purchase', 'display_name'])[0]
        )
       
        if not product_or_template.is_product_variant:
            basic_information['id'] = False
            combination_name = combination._get_combination_name()
            if combination_name:
                basic_information.update(
                    display_name=f"{basic_information['display_name']} ({combination_name})"
                )
       
        price = product_or_template.standard_price

        purchase_order_id = int(kwargs.get('id', 0))
   
        if purchase_order_id:
            purchase_order = request.env['purchase.order'].browse(purchase_order_id)
           
            if purchase_order:
                seller = product_or_template.seller_ids.filtered(lambda s: purchase_order.partner_id.id)
                if seller:
                    price = seller[0].price

        return dict(
            **basic_information,
            price=price
        )
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hello Muhammad Ihza Putra Handayani, 


    The issue seems to stem from the way you're handling the ID of the current model (product_or_template). 

    To ensure that you're getting the correct ID of the product or template, you should add a mechanism to 

    extract it directly from the product_or_template object, especially when product_or_template.is_product_variant is True.


    Here's how you can modify your function to correctly extract and use the ID of the product_or_template object.

// Code in comment //

    Hope this helps.

    

    If you need any help in customization feel free to contact us.

        

Thanks & Regards,

Email:  odoo@aktivsoftware.com           

Skype: kalpeshmaheshwari 

Ảnh đại diện
Huỷ bỏ

Code :

def _get_basic_product_information_purchase(self, product_or_template, pricelist, combination, **kwargs):
# Initialize basic information dictionary
basic_information = dict(
**product_or_template.read(['description_purchase', 'display_name'])[0]
)

# Add the product_or_template ID to the basic_information dictionary
basic_information['id'] = product_or_template.id

# If the product_or_template is not a product variant
if not product_or_template.is_product_variant:
basic_information['id'] = False # Reset ID to False
combination_name = combination._get_combination_name()
if combination_name:
basic_information.update(
display_name=f"{basic_information['display_name']} ({combination_name})"
)

# Get the standard price of the product_or_template
price = product_or_template.standard_price

# Get the purchase order ID from kwargs
purchase_order_id = int(kwargs.get('id', 0))

if purchase_order_id:
# Browse the purchase order using the ID
purchase_order = request.env['purchase.order'].browse(purchase_order_id)

if purchase_order:
# Find the seller linked to the purchase order partner
seller = product_or_template.seller_ids.filtered(lambda s: s.name.id == purchase_order.partner_id.id)
if seller:
# Use the seller's price if available
price = seller[0].price

# Return the basic information along with the price
return dict(
**basic_information,
price=price
)

Tác giả

thank you very much for your helps but it seems that it not reach what i desire. actually the id of what i am going to get is from purchase.order and if i try your below code i dont even get any id
but if try straight search of id in purchase order it worked well
price = product_or_template.standard_price
purchase_order = request.env['purchase.order'].search([('id', '=', self.id)])

for rec in purchase_order:
seller = product_or_template.seller_ids.filtered(lambda x: x.partner_id.id == rec.partner_id.id)
if seller:
price = seller[0].price

any idea? im stuck in this

Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 6 24
4145
0
thg 7 19
4941
2
thg 5 15
20710
2
thg 6 25
1305
3
thg 4 23
12000