Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
19081 มุมมอง

Hello all,

In the stock.picking model, I want to declare a new field (customer_of_division_id).

If the stock.picking has a value in his sale_id field, I would want to declare the field like this :

customer_of_division_id = fields.Many2one(related="sale_id.customer_of_division_id", 
domain="[('division_of_company_id','=',company_id)]",
string='Customer of the division')
If the stock.picking has NO value in his sale_id field, I would want to declare the field like this :
customer_of_division_id = fields.Many2one(related="partner_id.customer_of_division_id", 
domain="[('division_of_company_id','=',company_id)]",
string='Customer of the division')

How to achieve this?

Thanks all

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

I think you may use a compute Many2one field.

For eg:

customer_of_division_id = fields.Many2one(compute='_get_division_id', comodel_name='res.partner', string='Customer of the division', store=True)
 
@api.depends('sale_id','partner_id')
def _get_division_id(self):
    if self.sale_id:
        self.customer_of_division_id = self.sale_id.customer_of_division_id.id
    elif self.partner_id:
        self.customer_of_division_id = self.partner_id.customer_of_division_id.id
อวตาร
ละทิ้ง
ผู้เขียน

You are really a beast! I try this and I come back soon! Big thanks (once again)!

ผู้เขียน

It works perfectly. Your help is really appreciated here!

thank you :)

Related Posts ตอบกลับ มุมมอง กิจกรรม
3
ส.ค. 15
11929
2
มี.ค. 15
9293
0
เม.ย. 22
2188
1
มี.ค. 15
13861
0
มี.ค. 15
3782