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'
Odoo is the world's easiest all-in-one management software.
 It includes hundreds of business apps:
- CRM
 - e-Commerce
 - Akuntansi
 - Inventaris
 - PoS
 - Project
 - MRP
 
Pertanyaan ini telah diberikan tanda
            
                2
                
                    Replies
                
            
        
        
            
                1773
                
                    Tampilan
                
            
        
    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
Menikmati diskusi? Jangan hanya membaca, ikuti!
Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!
Daftar| Post Terkait | Replies | Tampilan | Aktivitas | |
|---|---|---|---|---|
| 
             | 
        
            
                
                1
            
            
             Okt 25  
         | 
        520 | ||
| 
             | 
        
            
                
                2
            
            
             Okt 25  
         | 
        361 | ||
| 
             | 
        
            
                
                0
            
            
             Okt 25  
         | 
        1197 | ||
| 
             | 
        
            
                
                3
            
            
             Okt 25  
         | 
        809 | ||
| 
     
            
                Add pdf file to quote
            
            
                    Diselesaikan
            
         
     | 
        
             | 
        
            
                
                1
            
            
             Sep 25  
         | 
        817 |