Skip to content

Commit

Permalink
[FIX] sale_operating_unit: allow to generate advance invoices with ou
Browse files Browse the repository at this point in the history
  • Loading branch information
alan196 committed Sep 8, 2023
1 parent 9a67f3d commit 2bcadfa
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
20 changes: 19 additions & 1 deletion sale_operating_unit/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,16 @@ def _check_company_operating_unit(self):
def _prepare_invoice(self):
self.ensure_one()
invoice_vals = super(SaleOrder, self)._prepare_invoice()
invoice_vals["operating_unit_id"] = self.operating_unit_id.id
invoice_vals.update({
"operating_unit_id": self.operating_unit_id.id,
"journal_id": self.env["account.journal"].search(
[
("operating_unit_id", "=", self.operating_unit_id.id),
("type", "=", "sale"),
],
limit=1,
).id,
})
return invoice_vals


Expand All @@ -81,3 +90,12 @@ class SaleOrderLine(models.Model):
string="Operating Unit",
store=True,
)

def _prepare_invoice_line(self, **optional_values):
invoice_line_vals = super()._prepare_invoice_line(**optional_values)
invoice_line_vals.update(
{
"operating_unit_id": self.order_id.operating_unit_id.id,
}
)
return invoice_line_vals
22 changes: 22 additions & 0 deletions sale_operating_unit/wizard/sale_make_invoice_advance.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from odoo import models
from odoo.exceptions import ValidationError


class SaleAdvancePaymentInv(models.TransientModel):
Expand All @@ -10,3 +11,24 @@ def _create_invoice(self, order, so_line, amount):
)
invoice.operating_unit_id = order.operating_unit_id.id
return invoice

def _prepare_invoice_values(self, order, so_line):
invoice_vals = super()._prepare_invoice_values(order, so_line)
journal = self.env["account.journal"].search(
[
("operating_unit_id", "=", order.operating_unit_id.id),
("type", "=", "sale"),
],
limit=1,
)
if not journal:
raise ValidationError(
_("You need to create a sales journal for this operating unit.")
)
invoice_vals.update(
{
"operating_unit_id": order.operating_unit_id.id,
"journal_id": journal.id,
}
)
return invoice_vals

0 comments on commit 2bcadfa

Please sign in to comment.