diff --git a/modules/purchase/CHANGELOG b/modules/purchase/CHANGELOG index 52a97c7a1d..8b4c0af027 100644 --- a/modules/purchase/CHANGELOG +++ b/modules/purchase/CHANGELOG @@ -1,3 +1,4 @@ +* Add pending, awaiting payment and partially paid to invoice state * Remove support for Python 3.7 * Add support for Python 3.11 * Add related stock moves and invoice lines on purchase line diff --git a/modules/purchase/purchase.py b/modules/purchase/purchase.py index 645b2a91fd..d189fcfeef 100644 --- a/modules/purchase/purchase.py +++ b/modules/purchase/purchase.py @@ -171,7 +171,9 @@ class Purchase( ], 'Invoice Method', required=True, states=_states) invoice_state = fields.Selection([ ('none', 'None'), - ('waiting', 'Waiting'), + ('pending', "Pending"), + ('awaiting payment', "Awaiting Payment"), + ('partially paid', "Partially Paid"), ('paid', 'Paid'), ('exception', 'Exception'), ], 'Invoice State', readonly=True, required=True, sort=False) @@ -377,6 +379,11 @@ class Purchase( [sql_table.state], ['cancelled'], where=sql_table.state == 'cancel')) + # Migration from 6.6: rename invoice state waiting to pending + cursor.execute(*sql_table.update( + [sql_table.invoice_state], ['pending'], + where=sql_table.invoice_state == 'waiting')) + @classmethod def order_number(cls, tables): table, _ = tables[None] @@ -601,8 +608,12 @@ class Purchase( return 'exception' elif all(i.state == 'paid' for i in invoices): return 'paid' + elif any(i.state == 'paid' for i in invoices): + return 'partially paid' + elif any(i.state == 'posted' for i in invoices): + return 'awaiting payment' else: - return 'waiting' + return 'pending' return 'none' get_shipments = get_shipments_returns('stock.shipment.in') diff --git a/modules/purchase/tests/scenario_purchase.rst b/modules/purchase/tests/scenario_purchase.rst index 7269e8b0f7..928707d7e4 100644 --- a/modules/purchase/tests/scenario_purchase.rst +++ b/modules/purchase/tests/scenario_purchase.rst @@ -182,7 +182,7 @@ Purchase 5 products:: >>> purchase.shipment_state 'waiting' >>> purchase.invoice_state - 'waiting' + 'pending' >>> len(purchase.moves), len(purchase.shipment_returns), len(purchase.invoices) (2, 0, 1) >>> invoice, = purchase.invoices @@ -219,7 +219,7 @@ Post invoice and check no new invoices:: >>> purchase.shipment_state 'waiting' >>> purchase.invoice_state - 'waiting' + 'awaiting payment' >>> len(purchase.moves), len(purchase.shipment_returns), len(purchase.invoices) (2, 0, 1) @@ -284,7 +284,7 @@ Validate Shipments:: Open supplier invoice:: >>> purchase.invoice_state - 'waiting' + 'pending' >>> invoice, = purchase.invoices >>> invoice.type 'in' @@ -367,7 +367,7 @@ Check Return Shipments:: >>> return_.shipment_state 'received' >>> return_.invoice_state - 'waiting' + 'pending' Open supplier credit note:: @@ -406,7 +406,7 @@ Mixing return and purchase:: >>> mix.shipment_state 'waiting' >>> mix.invoice_state - 'waiting' + 'pending' >>> len(mix.moves), len(mix.shipment_returns), len(mix.invoices) (2, 1, 1) @@ -518,7 +518,7 @@ Purchase services:: >>> service_purchase.shipment_state 'none' >>> service_purchase.invoice_state - 'waiting' + 'pending' >>> service_invoice, = service_purchase.invoices Pay the service invoice:: diff --git a/modules/purchase_secondary_unit/tests/scenario_purchase_secondary_unit.rst b/modules/purchase_secondary_unit/tests/scenario_purchase_secondary_unit.rst index 4644b05286..e81595248a 100644 --- a/modules/purchase_secondary_unit/tests/scenario_purchase_secondary_unit.rst +++ b/modules/purchase_secondary_unit/tests/scenario_purchase_secondary_unit.rst @@ -115,7 +115,7 @@ Confirm purchase:: >>> purchase.click('quote') >>> purchase.click('confirm') >>> purchase.invoice_state - 'waiting' + 'pending' >>> purchase.shipment_state 'waiting' diff --git a/modules/sale/CHANGELOG b/modules/sale/CHANGELOG index b54893f841..ba450b1974 100644 --- a/modules/sale/CHANGELOG +++ b/modules/sale/CHANGELOG @@ -1,3 +1,4 @@ +* Add pending, awaiting payment and partially paid to invoice state * Remove support for Python 3.7 * Add support for Python 3.11 * Add related stock moves and invoice lines on sale line diff --git a/modules/sale/sale.py b/modules/sale/sale.py index 93a737c775..a116010891 100644 --- a/modules/sale/sale.py +++ b/modules/sale/sale.py @@ -199,7 +199,9 @@ class Sale( invoice_method_string = invoice_method.translated('invoice_method') invoice_state = fields.Selection([ ('none', 'None'), - ('waiting', 'Waiting'), + ('pending', "Pending"), + ('awaiting payment', "Awaiting Payment"), + ('partially paid', "Partially Paid"), ('paid', 'Paid'), ('exception', 'Exception'), ], 'Invoice State', readonly=True, required=True, sort=False) @@ -377,6 +379,11 @@ class Sale( [sql_table.state], ['cancelled'], where=sql_table.state == 'cancel')) + # Migration from 6.6: rename invoice state waiting to pending + cursor.execute(*sql_table.update( + [sql_table.invoice_state], ['pending'], + where=sql_table.invoice_state == 'waiting')) + @classmethod def order_number(cls, tables): table, _ = tables[None] @@ -611,8 +618,12 @@ class Sale( return 'exception' elif all(i.state == 'paid' for i in invoices): return 'paid' + elif any(i.state == 'paid' for i in invoices): + return 'partially paid' + elif any(i.state == 'posted' for i in invoices): + return 'awaiting payment' else: - return 'waiting' + return 'pending' return 'none' get_shipments = get_shipments_returns('stock.shipment.out') diff --git a/modules/sale/tests/scenario_sale.rst b/modules/sale/tests/scenario_sale.rst index 2be93f92f8..4afbeb6ee3 100644 --- a/modules/sale/tests/scenario_sale.rst +++ b/modules/sale/tests/scenario_sale.rst @@ -172,7 +172,7 @@ Sale 5 products:: >>> sale.shipment_state 'waiting' >>> sale.invoice_state - 'waiting' + 'pending' >>> len(sale.shipments), len(sale.shipment_returns), len(sale.invoices) (1, 0, 1) >>> invoice, = sale.invoices @@ -210,6 +210,8 @@ Post invoice and check no new invoices:: >>> sale.reload() >>> len(sale.shipments), len(sale.shipment_returns), len(sale.invoices) (1, 0, 1) + >>> sale.invoice_state + 'awaiting payment' Testing the report:: @@ -273,7 +275,7 @@ Open customer invoice:: >>> sale.reload() >>> sale.invoice_state - 'waiting' + 'pending' >>> invoice, = sale.invoices >>> invoice.type 'out' @@ -315,7 +317,7 @@ Sale 5 products with shipment method 'on invoice':: >>> sale.shipment_state 'none' >>> sale.invoice_state - 'waiting' + 'pending' >>> len(sale.shipments), len(sale.shipment_returns), len(sale.invoices) (0, 0, 1) @@ -426,7 +428,7 @@ Check Return:: >>> return_.shipment_state 'waiting' >>> return_.invoice_state - 'waiting' + 'pending' >>> (len(return_.shipments), len(return_.shipment_returns), ... len(return_.invoices)) (0, 2, 1) @@ -459,7 +461,7 @@ Check Return:: >>> return_.shipment_state 'sent' >>> return_.invoice_state - 'waiting' + 'awaiting payment' >>> (len(return_.shipments), len(return_.shipment_returns), ... len(return_.invoices)) (0, 2, 2) @@ -489,7 +491,7 @@ Mixing return and sale:: >>> mix.shipment_state 'waiting' >>> mix.invoice_state - 'waiting' + 'pending' >>> len(mix.shipments), len(mix.shipment_returns), len(mix.invoices) (1, 1, 1) @@ -589,7 +591,7 @@ Sale services:: >>> service_sale.shipment_state 'none' >>> service_sale.invoice_state - 'waiting' + 'pending' >>> service_invoice, = service_sale.invoices Pay the service invoice:: @@ -691,6 +693,9 @@ invoices:: >>> invoice.reload() >>> invoice.state 'paid' + >>> sale.reload() + >>> sale.invoice_state + 'partially paid' >>> invoice_line.reload() >>> stock_move, = invoice_line.stock_moves >>> stock_move.quantity diff --git a/modules/sale_secondary_unit/tests/scenario_sale_secondary_unit.rst b/modules/sale_secondary_unit/tests/scenario_sale_secondary_unit.rst index 1cbc79722d..668aa303c6 100644 --- a/modules/sale_secondary_unit/tests/scenario_sale_secondary_unit.rst +++ b/modules/sale_secondary_unit/tests/scenario_sale_secondary_unit.rst @@ -102,7 +102,7 @@ Confirm sale:: >>> sale.click('quote') >>> sale.click('confirm') >>> sale.invoice_state - 'waiting' + 'pending' >>> sale.shipment_state 'waiting'