From 62bedbbb407dfdb26c7434fcbe89af4147c3d9c1 Mon Sep 17 00:00:00 2001 From: Cybrosys Technologies Date: Tue, 15 Jul 2025 19:55:12 +0530 Subject: [PATCH] July 15: [FIX] Bug Fixed 'payment_status_in_sale' --- payment_status_in_sale/doc/RELEASE_NOTES.md | 9 +++- payment_status_in_sale/models/sale_order.py | 48 ++++++++++----------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/payment_status_in_sale/doc/RELEASE_NOTES.md b/payment_status_in_sale/doc/RELEASE_NOTES.md index 440cfa14c..3ac9a32e0 100644 --- a/payment_status_in_sale/doc/RELEASE_NOTES.md +++ b/payment_status_in_sale/doc/RELEASE_NOTES.md @@ -6,6 +6,11 @@ - Initial commit for Sale Order Payment Status #### 25.06.2025 -#### Version 18.0.1.0.0 +#### Version 18.0.1.0.1 +##### ADD +- Bug fixed to ensure the correct payment status is reflected when credit notes are created. + +#### 15.07.2025 +#### Version 18.0.1.0.2 ##### ADD -- Bug fixed to ensure the correct payment status is reflected when credit notes are created. \ No newline at end of file +- Issue resolved in computing the amount due by considering only posted invoices. \ No newline at end of file diff --git a/payment_status_in_sale/models/sale_order.py b/payment_status_in_sale/models/sale_order.py index 687f549c6..edb6b91f3 100644 --- a/payment_status_in_sale/models/sale_order.py +++ b/payment_status_in_sale/models/sale_order.py @@ -52,31 +52,29 @@ class SaleOrder(models.Model): will be either in paid,not paid,partially paid, reversed etc. """ for order in self: order.payment_status = 'No invoice' - payment_states = order.invoice_ids.mapped('payment_state') - status_length = len(payment_states) - if 'partial' in payment_states: - order.payment_status = 'Partially Paid' - elif 'not_paid' in payment_states and any( - (True for x in ['paid', 'in_payment', 'partial'] if - x in payment_states)): - order.payment_status = 'Partially Paid' - elif 'not_paid' in payment_states and status_length == \ - payment_states.count('not_paid'): - order.payment_status = 'Not Paid' - elif 'paid' in payment_states and status_length == \ - payment_states.count('paid') and order.amount_due == 0: - order.payment_status = 'Paid' - elif 'paid' in payment_states and status_length == \ - payment_states.count('paid') and order.amount_due != 0: - order.payment_status = 'Partially Paid' - elif 'in_payment' in payment_states and status_length == \ - payment_states.count('in_payment'): - order.payment_status = 'In Payment' - elif 'reversed' in payment_states and status_length == \ - payment_states.count('reversed'): - order.payment_status = 'Reversed' - else: + posted_invoices = order.invoice_ids.filtered( + lambda x: x.state == 'posted') + if not posted_invoices: order.payment_status = 'No invoice' + else: + payment_states = posted_invoices.mapped('payment_state') + status_length = len(payment_states) + if order.amount_due > 0: + if 'partial' in payment_states or 'not_paid' in payment_states: + order.payment_status = 'Partially Paid' + elif 'not_paid' in payment_states and status_length == payment_states.count( + 'not_paid'): + order.payment_status = 'Not Paid' + elif order.amount_due <= 0: # Changed to <= 0 to handle overpayments or credit notes + if 'paid' in payment_states and status_length == payment_states.count( + 'paid'): + order.payment_status = 'Paid' + elif 'in_payment' in payment_states and status_length == payment_states.count( + 'in_payment'): + order.payment_status = 'In Payment' + elif 'reversed' in payment_states and status_length == payment_states.count( + 'reversed'): + order.payment_status = 'Reversed' @api.depends('invoice_ids') def _compute_invoice_state(self): @@ -99,7 +97,7 @@ class SaleOrder(models.Model): for rec in self: total_invoiced = 0 total_paid = 0 - for invoice in rec.invoice_ids: + for invoice in rec.invoice_ids.filtered(lambda x: x.state == 'posted'): if invoice.move_type == 'out_invoice': # Regular invoices total_invoiced += invoice.amount_total total_paid += invoice.amount_total - invoice.amount_residual