1 parent
cd6c759e05
commit
df1021103f
4 files changed
+16
-18
No files matched your search
@@ -1,3 +1,4 @@
|
||||
* Add company argument to check credit limit
|
||||
|
||||
Version 7.4.0 - 2024-11-04
|
||||
--------------------------
|
||||
|
||||
@@ -39,7 +39,7 @@ class Party(metaclass=PoolMeta):
|
||||
'Return models to lock when checking credit limit'
|
||||
return ['account.move.line']
|
||||
|
||||
def check_credit_limit(self, amount, origin=None):
|
||||
def check_credit_limit(self, amount, company, origin=None):
|
||||
'''
|
||||
Check if amount will not reach credit limit for party
|
||||
If origin is set and user is in group credit_limit then a warning will
|
||||
@@ -53,16 +53,13 @@ class Party(metaclass=PoolMeta):
|
||||
Dunning = None
|
||||
User = pool.get('res.user')
|
||||
Group = pool.get('res.group')
|
||||
Company = pool.get('company.company')
|
||||
Lang = pool.get('ir.lang')
|
||||
Warning = pool.get('res.user.warning')
|
||||
|
||||
if self.credit_limit_amount is None:
|
||||
credit_limit_amount = self.get_multivalue(
|
||||
'credit_limit_amount', company=company.id)
|
||||
if credit_limit_amount is None:
|
||||
return
|
||||
company_id = Transaction().context.get('company')
|
||||
if company_id is None or company_id < 0:
|
||||
return
|
||||
company = Company(company_id)
|
||||
|
||||
def in_group():
|
||||
group = Group(ModelData.get_id('account_credit_limit',
|
||||
|
||||
@@ -63,24 +63,24 @@ class AccountCreditLimitTestCase(CompanyTestMixin, ModuleTestCase):
|
||||
}])
|
||||
self.assertEqual(party.credit_amount, Decimal(100))
|
||||
self.assertEqual(party.credit_limit_amount, None)
|
||||
party.check_credit_limit(Decimal(0))
|
||||
party.check_credit_limit(Decimal(0), 'test')
|
||||
party.check_credit_limit(Decimal(100))
|
||||
party.check_credit_limit(Decimal(100), 'test')
|
||||
party.check_credit_limit(Decimal(0), company)
|
||||
party.check_credit_limit(Decimal(0), company, 'test')
|
||||
party.check_credit_limit(Decimal(100), company)
|
||||
party.check_credit_limit(Decimal(100), company, 'test')
|
||||
party.credit_limit_amount = Decimal(0)
|
||||
party.save()
|
||||
self.assertRaises(UserError, party.check_credit_limit,
|
||||
Decimal(0))
|
||||
Decimal(0), company)
|
||||
self.assertRaises(UserWarning, party.check_credit_limit,
|
||||
Decimal(0), 'test')
|
||||
Decimal(0), company, 'test')
|
||||
party.credit_limit_amount = Decimal(200)
|
||||
party.save()
|
||||
party.check_credit_limit(Decimal(0))
|
||||
party.check_credit_limit(Decimal(0), 'test')
|
||||
party.check_credit_limit(Decimal(0), company)
|
||||
party.check_credit_limit(Decimal(0), company, 'test')
|
||||
self.assertRaises(UserError, party.check_credit_limit,
|
||||
Decimal(150))
|
||||
Decimal(150), company)
|
||||
self.assertRaises(UserWarning, party.check_credit_limit,
|
||||
Decimal(150), 'test')
|
||||
Decimal(150), company, 'test')
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
@@ -23,7 +23,7 @@ class Sale(metaclass=PoolMeta):
|
||||
if sale.must_check_credit_limit():
|
||||
party = sale.invoice_party or sale.party
|
||||
party.check_credit_limit(
|
||||
sale.credit_limit_amount, origin=str(sale))
|
||||
sale.credit_limit_amount, sale.company, origin=str(sale))
|
||||
super(Sale, cls).confirm(sales)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user