From 3c5524a912488df579b30c8e1bc79993386eff8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesu=CC=81s=20Alan=20Ramos=20Rodri=CC=81guez?= Date: Fri, 6 Oct 2023 05:36:55 -0600 Subject: [PATCH] [FIX] purchse_operating_unit: allow to generate invoices from purchase orders --- purchase_operating_unit/models/purchase_order.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/purchase_operating_unit/models/purchase_order.py b/purchase_operating_unit/models/purchase_order.py index 07810dfe0a..810f76fe7d 100644 --- a/purchase_operating_unit/models/purchase_order.py +++ b/purchase_operating_unit/models/purchase_order.py @@ -50,7 +50,21 @@ def _check_company_operating_unit(self): def _prepare_invoice(self): invoice_vals = super()._prepare_invoice() - invoice_vals["operating_unit_id"] = self.operating_unit_id.id + journal = self.env["account.journal"].search( + [ + ("operating_unit_id", "=", self.operating_unit_id.id), + ("type", "=", "purchase"), + ], + limit=1, + ) + if not journal: + raise ValidationError( + _("You need to create a purchase journal for this operating unit.") + ) + invoice_vals.update({ + "journal_id": journal.id, + "operating_unit_id": self.operating_unit_id.id, + }) return invoice_vals