Skip to Content
Menu
This question has been flagged
3 Replies
3447 Views

My code runs, but it doesnt fill anything on my one2many list

class fido_reporting(models.Model):
_name = 'fido.reporting'
date = fields.Date(default=fields.Date.today(), string='Date')
incedent = fields.Text(string='Incident')
fido_reporting_ids = fields.One2many('fido.line.report', 'line_report_id', compute="compute_report")

@api.one
@api.depends('date')
def compute_report(self):
report_data = self.env['account.invoice'].search([('date_invoice','=',self.date),('journal_id','=',"Customer Invoices"),('state','!=',"Draft")])
for reports in report_data:
for line_records in reports.invoice_line_ids:
params = {'line_report_id':self.id, 'name': reports.partner_id.name, 'product': line_records.product_id.name, 'quantity': 10, 'price' : 10.0, 'amount': 10.0}
# print params
print params
self.fido_reporting_ids.write(params)
Avatar
Discard
Author Best Answer

this is my solution to it 

for reports in report_data: 
for line_records in reports.invoice_line_ids:
params = {'line_report_id':self.id, 'name': reports.partner_id.name, 'product': line_records.product_id.name, 'quantity': line_records.quantity, 'price' : line_records.price_unit, 'amount': line_records.price_subtotal}
#print params
self.fido_reporting_ids |= self.env['fido.line.report'].create(params)
Avatar
Discard
Best Answer
try this:

fido_obj= self.env['fido.line.report']
fido_obj.create(params)
Avatar
Discard
Best Answer

instead of write just use create here , the foreign key line_report_id    automatically link this  record with the current id 

Avatar
Discard