Advertisement
rht_odoo

[QW][4115887] Analytic account

Aug 19th, 2024 (edited)
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. # Done by RHT on the 19/08/2024
  2. # Pastebin : https://pastebin.com/yvmTQ0bJ
  3. # Need : Sysax always creates sale orders from an opportunity. We need to have one analytic account per opportunity, so the idea is to link the same analytic account to every sale orders created from the same opportunity. 
  4. # Task : https://www.odoo.com/odoo/project.task/4115887
  5. for so in records:
  6.     if so.opportunity_id:
  7.         if so.opportunity_id.x_studio_analytic_account_id:
  8.             so["analytic_account_id"] = so.opportunity_id.x_studio_analytic_account_id.id
  9.         if not so.opportunity_id.x_studio_analytic_account_id :
  10.             ana_account = env['account.analytic.account'].create(
  11.                 {
  12.                     'plan_id' : 1,
  13.                     'company_id' : so.company_id.id,
  14.                     'partner_id' : so.partner_id.id,
  15.                     'name' : so.opportunity_id.name,
  16.                    
  17.                 })
  18.            
  19.             so.opportunity_id["x_studio_analytic_account_id"] = ana_account
  20.             so["analytic_account_id"] = ana_account
  21.        
  22.        
  23.  
  24.  
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement