Hello odoo community, please i am new into odoo and need help. I have a class project_analysis that has project_line_ids field which is a many2one field refrencing another model AccountInvoiceLine which takes all amount and description per line for single project ( project_analysis). I therefore added a computed field total_amount in the first model and tried to write a function which will refrence the second model so i can calculate all the money spent in a particular project.
code**
class project_analysis(models.Model): _name = 'fastra.project.analysis' #_inherits = ['account']
status is used when payments have been registered for the entirety of the invoice in a journal configured to post entries at bank reconciliation only, and some of them haven't been reconciled with a bank statement line yet.\n" " * The 'Paid 'status is set automatically when the invoice is paid. Its related journal entries may or may not be reconciled.\n" " * The 'Cancelled' status is used when user cancel invoice.") date_invoice = fields.Date(string='Date', readonly=True, states={' draft': [('readonly', False)]}, index=True, help="Keep empty to use the current date", copy=False) partner_id = fields.Many2one('res.partner', string='
vat = fields.Monetary(string='VAT')
pr = fields.Monetary(string='P.R')
po_number = fields.Char('PO Number')
project = fields.Char('Project Name')
wht = fields.Monetary('WHT')
invoice_line_ids = fields.One2many('project.analysis.line', 'job_line_ids', string='Project Lines', readonly=True, states={'draft': [('readonly', False)]}, copy=True)
amount = fields.Monetary('Total Amount Paid')
amount_total = fields.Float(string='Total Amount', compute='_compute_total_amount', store=False, # optional )
# method with the value computation logic for book age since the realease date: @api.multi @api.depends('invoice_line_ids.job_line_ids') def _compute_total_amount(self): totalAmount = 0 for a in self.filtered('invoice_line_ids.job_line_ids '): totalAmount += a.amount a.amount_total = totalAmount
class AccountInvoiceLine(models.Model): _name = "project.analysis.line" _description = "Project Line"
job_id = fields.Many2one('product.product', string ='Job', ondelete='restrict', index=True)
job_line_ids = fields.Many2one( 'fastra.project.analysis', string='Job Reference', ondelete='cascade', index=True)
amount = fields.Float(string='Amount', required=True)
#price_total = fields.Monetary(string='Amount',readonly=True, help="Total amount for the job")
account_analytic_id = fields.Many2one('account.analytic.account', string='Project Account')
name = fields.Text(string='Description', required=True)
account_id = fields.Many2one('account.account', string='Account', domain=[('deprecated', '=', False)], help= "The expense account related to the selected job.")