İçereği Atla
Menü
Bu soru işaretlendi
3 Cevaplar
3646 Görünümler


from odoo import models, fields, api, _


class ProductRejection(models.Model):

_name = 'product.rejection'

pr_type_of_order = fields.Selection([('SO', 'Sale Order'), ('PO', 'Purchase Order')], string="Order Type")
pr_customer_name = fields.Many2one('sale.order',string="Vendor/Customer")
pr_order_no = fields.Many2one('sale.order',string="PO/SO No.")
pr_rejection_date = fields.Date("Date Of Rejection")
pr_product_name = fields.Many2one('product.product',string='Product Name')
pr_presentation = fields.Char("Presentation")
pr_reason = fields.Text("Reason Of Rejection")
pr_notes = fields.Text("Receiving Notes")
pr_status = fields.Selection([('new','New'),('confirm','Confirmed')],string="Status")

@api.onchange('pr_type_of_order')
def update_customer(self):
result = {}
if self.pr_type_of_order == 'SO':
sale_customer_obj = self.env['sale.order']
sale_customer_ids = sale_customer_obj.search(['partner_id'])
for record in sale_customer_ids:
cust_name = []
cust_name.append(record.id)
result = {'domain': {'pr_customer_name': [('id', 'in', cust_name)]}}
return result
else:
if self.pr_type_of_order == 'PO':
sale_customer_obj = self.env['purchase.order']
sale_customer_ids = sale_customer_obj.search(['partner_id'])
for record in sale_customer_ids:
cust_name1 = []
cust_name1.append(record.id)
result = {'domain': {'pr_customer_name': [('id', 'in', cust_name1)]}}
return result






Avatar
Vazgeç
En İyi Yanıt

Hi Ashutosh,

You cannot show the records of the different objects in a single m2o field. Like you cannot show purchase.orders in the sale.order m2o field.

For that, you need to create two m2o fields (sale.order, purchase.order) for each object. Now, based on the selection field's value, you can hide those fields using attrs in the XML file.


Avatar
Vazgeç
En İyi Yanıt

@api.multi

Avatar
Vazgeç
Üretici En İyi Yanıt

I want to work it on onchange function. Please can you check my onchange function code. I think I'm missing something in that.

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
2
Nis 20
4611
1
Nis 20
3576
2
Eyl 19
9173
2
Haz 19
5624
0
Haz 21
3383