Hello, could someone help me with the creation of journal entries?
I am creating a custom module and I want to create journal entries with a button, the problem I have is that if there is more than one line or product the values of my journal entries are always those of the first line or product, for example if I have 3 products 3 journal items are created but all take the same value which would be the first product.
this is my PY
def action_entry(self):
for rec in self:
for line in rec.avg_landed_cost_lines:
debit = line.average_landed_cost
credit = line.average_landed_cost
move = {
'name': '/',
'journal_id': rec.journal_id.id,
'date': rec.fecha,
'ref': rec.name,
'line_ids': [(0, 0, {
'name': line.product_id.name or '/',
'debit': debit,
'account_id': line.product_id.property_account_expense_id.id,
'partner_id': rec.order_id.partner_id.id,
}), (0, 0, {
'name': line.product_id.name or '/',
'credit': credit,
'account_id': line.product_id.property_account_income_id.id,
'partner_id': rec.order_id.partner_id.id,
})]
}
move_id = line.env['account.move'].create(move)
move_id.post()
return rec.write({'state': 'progress', 'move_id': move_id.id})
thanks!