Skip to content

Commit

Permalink
[IMP] Prevent validating a prepaid supplier invoice if the custom acc…
Browse files Browse the repository at this point in the history
…ount does not contain enough money
  • Loading branch information
florian-dacosta committed Mar 26, 2024
1 parent 3f4fe55 commit 6ad332a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
5 changes: 4 additions & 1 deletion project_invoicing_subcontractor/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,12 @@ def _check_invoice_mode_validity(self):
)

def _post(self, soft=True):
res = super()._post(soft=soft)
for move in self:
if move.subcontractor_state_color == "danger":
raise exceptions.UserError(move.subcontractor_state_message)
move._check_invoice_mode_validity()
res = super()._post(soft=soft)
for move in self:
if move.is_supplier_prepaid:
move._manage_prepaid_lines()
move.compute_enought_analytic_amount(partner_id=move.customer_id.id)
Expand Down
14 changes: 8 additions & 6 deletions project_invoicing_subcontractor/tests/test_invoicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,8 @@ def test_prepaid_invoicing_process_same_project(self):
self.assertTrue(demo_invoice.to_pay)

# set admin invoice one day later to be sure demo invoice has priority
admin_invoice.write({"invoice_date": date.today() + timedelta(days=1)})
admin_invoice.action_post()
self.env["account.move"].compute_enought_analytic_amount()
self.assertFalse(admin_invoice.to_pay)
self.assertTrue(demo_invoice.to_pay)

# Add customer invoice so there is enough amount to validate the admin invoice
# but it is not paid
customer_invoice2 = self._create_prepaid_customer_invoice(
1.99, self.line_5_2.project_id.analytic_account_id
)
Expand All @@ -230,6 +226,12 @@ def test_prepaid_invoicing_process_same_project(self):
0.01, self.line_5_2.project_id.analytic_account_id
)
customer_invoice3.action_post()
admin_invoice.write({"invoice_date": date.today() + timedelta(days=1)})
admin_invoice.action_post()
self.env["account.move"].compute_enought_analytic_amount()
self.assertFalse(admin_invoice.to_pay)
self.assertTrue(demo_invoice.to_pay)

self.env["account.payment.register"].with_context(
active_ids=customer_invoice2.ids, active_model="account.move"
).create({})._create_payments()
Expand Down

0 comments on commit 6ad332a

Please sign in to comment.