From 557242df0fcffef98a13b5f6d7412751557aa52e Mon Sep 17 00:00:00 2001 From: Kaynnan Lemes Date: Wed, 14 Aug 2024 15:05:43 -0300 Subject: [PATCH] [IMP] hr_expense_invoice: prepare invoice values --- hr_expense_invoice/models/hr_expense.py | 50 ++++++++++++------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/hr_expense_invoice/models/hr_expense.py b/hr_expense_invoice/models/hr_expense.py index 1a4bf4a90..494df041a 100644 --- a/hr_expense_invoice/models/hr_expense.py +++ b/hr_expense_invoice/models/hr_expense.py @@ -24,32 +24,32 @@ class HrExpense(models.Model): copy=False, ) - def action_expense_create_invoice(self): - invoice_lines = [ - ( - 0, - 0, - { - "product_id": self.product_id.id, - "name": self.name, - "price_unit": self.unit_amount, - "quantity": self.quantity, - "account_id": self.account_id.id, - "analytic_account_id": self.analytic_account_id.id, - "tax_ids": [(6, 0, self.tax_ids.ids)], - }, - ) + def _prepare_invoice_line_values(self): + """Prepare the values for the invoice lines based on the expense.""" + return [ + { + "product_id": self.product_id.id, + "name": self.name, + "price_unit": self.unit_amount, + "quantity": self.quantity, + "account_id": self.account_id.id, + "analytic_account_id": self.analytic_account_id.id, + "tax_ids": [(6, 0, self.tax_ids.ids)], + } ] - invoice = self.env["account.move"].create( - [ - { - "ref": self.reference, - "move_type": "in_invoice", - "invoice_date": self.date, - "invoice_line_ids": invoice_lines, - } - ] - ) + + def _prepare_invoice_values(self): + invoice_lines = self._prepare_invoice_line_values() + return { + "name": "/", + "ref": self.reference, + "move_type": "in_invoice", + "invoice_date": self.date, + "invoice_line_ids": [(0, 0, line) for line in invoice_lines], + } + + def action_expense_create_invoice(self): + invoice = self.env["account.move"].create(self._prepare_invoice_values()) attachments = self.env["ir.attachment"].search( [("res_model", "=", self._name), ("res_id", "in", self.ids)] )