Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
1519 มุมมอง
class ResPartner(models.Model):   
_inherit = 'res.partner'
type_customer = fields.Selection([('normal','Normal'), ('gold', 'Gold')], string='Type customer', default=type_cus[0][0])
@api.depends('total_invoiced')
def _compute_type_customer(self):
for rec in self:
if rec.total_invoiced > 1000:
rec.type_customer = 'Gold'
else:
rec.type_customer = 'Normal'


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

Hi,

To change the value of the field type_customer according to the total_invoice amount.Updated the code like this:

class ResPartner(models.Model): 
_inherit = 'res.partner'
type_customer = fields.Selection([('normal', 'Normal'), ('gold', 'Gold')], string='Type customer', compute='_compute_type_customer')
def _compute_type_customer(self):
for rec in self:
total_invoiced = sum(rec.env['account.move'].browse(rec.id).mapped('amount_total_signed'))
if total_invoiced > 1000:
rec.type_customer = 'Gold'
else:
rec.type_customer = 'Normal'

Regards

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

Hi,

To get the total invoiced amount of the customer, you can read it from account.move.line using the search orm with proper domain in search function.

domain = []

self.env['account.move.line'].search(domain)


Thanks

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ก.ย. 25
176
error when adding the sales app แก้ไขแล้ว
2
ก.ย. 25
402
3
ก.ย. 25
485
3
ก.ย. 25
557
How to merge companies แก้ไขแล้ว
4
ส.ค. 25
1678