Skip to content

Commit

Permalink
[FIX] sale_invoice_plan: first invoice marked all plan lines as invoiced
Browse files Browse the repository at this point in the history
The Advance Payment use case still doesn't work, but at least invoicing
one by one works.
  • Loading branch information
dreispt committed Nov 24, 2023
1 parent 05610a4 commit a52b260
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
22 changes: 10 additions & 12 deletions sale_invoice_plan/models/sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ def _compute_invoice_plan_process(self):
for rec in self:
has_invoice_plan = rec.use_invoice_plan and rec.invoice_plan_ids
to_invoice = rec.invoice_plan_ids.filtered(lambda l: not l.invoiced)
invoice_plan_process = False
if rec.state == "sale" and has_invoice_plan and to_invoice:
if rec.invoice_status in [
"to invoice",
"no",
] and "advance" in to_invoice.mapped("invoice_type"):
invoice_plan_process = True
rec.invoice_plan_process = invoice_plan_process
rec.invoice_plan_process = (
rec.state == "sale"
and has_invoice_plan
and to_invoice
and rec.invoice_status in ["to invoice", "no"]
and "advance" in to_invoice.mapped("invoice_type")
)

@api.constrains("invoice_plan_ids")
def _check_invoice_plan_total_percent(self):
Expand Down Expand Up @@ -136,12 +135,11 @@ def _next_date(self, installment_date, interval, interval_type):
def _create_invoices(self, grouped=False, final=False, date=None):
moves = super()._create_invoices(grouped=grouped, final=final, date=date)
if self.use_invoice_plan:
plan = self.env["sale.invoice.plan"].search(
[("sale_id", "=", self.id)], limit=1
)
plan = self.invoice_plan_ids.filtered(
lambda x: x.to_invoice and x.invoice_type == "installment"
)[:1]
for move in moves:
plan._compute_new_invoice_quantity(move)
move.invoice_date = plan.plan_date
move._compute_date()
plan.invoice_move_ids += moves
return moves
8 changes: 4 additions & 4 deletions sale_invoice_plan/wizard/sale_make_invoice_advance.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class SaleAdvancePaymentInv(models.TransientModel):

def _create_invoices(self, sale_orders):
invoice = super()._create_invoices(sale_orders)
for sale in sale_orders:
if sale.use_invoice_plan:
plan = self.env["sale.invoice.plan"].search([("sale_id", "=", sale.id)])
plan.invoice_move_ids += invoice
# Link created Invoices to the Invoice Plan Lines
for sale in sale_orders.filtered(lambda x: x.use_invoice_plan):
plan = sale.invoice_plan_ids.filtered(lambda x: x.to_invoice)
plan.invoice_move_ids += invoice
return invoice

0 comments on commit a52b260

Please sign in to comment.