changeset e6610aa40df9 in modules/sale_credit_limit:default
details:
https://hg.tryton.org/modules/sale_credit_limit?cmd=changeset;node=e6610aa40df9
description:
Check credit on confirmation
The proceed method is executed in the queue since rev b72e1e9b9097
This means the warning raised is never shown to the user. So it is
better to
raise it on confirmation.
issue8726
review264411006
diffstat:
doc/index.rst | 2 +-
party.py | 2 +-
sale.py | 9 ++++++---
tests/test_sale_credit_limit.py | 11 +++++------
4 files changed, 13 insertions(+), 11 deletions(-)
diffs (74 lines):
diff -r 84cf6de68b4b -r e6610aa40df9 doc/index.rst
--- a/doc/index.rst Mon May 06 15:11:09 2019 +0200
+++ b/doc/index.rst Thu Oct 24 19:12:01 2019 +0200
@@ -3,4 +3,4 @@
The sale_credit_limit module adds confirmed sale but not yet invoiced to the
"Credit Amount" of the Party and check the credit limit of the party when
-processing a sale.
+confirming a sale.
diff -r 84cf6de68b4b -r e6610aa40df9 party.py
--- a/party.py Mon May 06 15:11:09 2019 +0200
+++ b/party.py Thu Oct 24 19:12:01 2019 +0200
@@ -28,7 +28,7 @@
sales = Sale.search([
('party', 'in', [p.id for p in parties]),
- ('state', '=', 'processing'),
+ ('state', 'in', ['confirmed', 'processing']),
])
for sale in sales:
amount = 0
diff -r 84cf6de68b4b -r e6610aa40df9 sale.py
--- a/sale.py Mon May 06 15:11:09 2019 +0200
+++ b/sale.py Thu Oct 24 19:12:01 2019 +0200
@@ -1,5 +1,6 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
+from trytond.model import ModelView, Workflow
from trytond.pool import PoolMeta
__all__ = ['Sale']
@@ -9,9 +10,11 @@
__name__ = 'sale.sale'
@classmethod
- def proceed(cls, sales):
+ @ModelView.button
+ @Workflow.transition('confirmed')
+ def confirm(cls, sales):
for sale in sales:
- if sale.state == 'confirmed' and sale.shipment_method == 'order':
+ if sale.shipment_method == 'order':
sale.party.check_credit_limit(sale.untaxed_amount,
origin=str(sale))
- return super(Sale, cls).proceed(sales)
+ super(Sale, cls).confirm(sales)
diff -r 84cf6de68b4b -r e6610aa40df9 tests/test_sale_credit_limit.py
--- a/tests/test_sale_credit_limit.py Mon May 06 15:11:09 2019 +0200
+++ b/tests/test_sale_credit_limit.py Thu Oct 24 19:12:01 2019 +0200
@@ -95,19 +95,18 @@
}])
self.assertEqual(party.credit_amount, Decimal('100'))
Sale.quote([sale])
- Sale.confirm([sale])
+ # Test limit reaches
+ self.assertRaises(UserWarning, Sale.confirm, [sale])
self.assertEqual(party.credit_amount, Decimal('100'))
- # Test limit reaches
- self.assertRaises(UserWarning, Sale.process, [sale])
# Increase limit
party.credit_limit_amount = Decimal('200')
party.save()
# process should work
- Sale.process([sale])
- self.assertEqual(sale.state, 'processing')
+ Sale.confirm([sale])
+ self.assertEqual(sale.state, 'confirmed')
self.assertEqual(party.credit_amount, Decimal('150'))
- # Re-process
+ # Process
Sale.process([sale])
# Decrease limit
party.credit_limit_amount = Decimal('100')