/usr/lib/python2.7/dist-packages/trytond/modules/sale_credit_limit/tests/test_sale_credit_limit.py is in tryton-modules-sale-credit-limit 4.2.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | # This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import unittest
from decimal import Decimal
import trytond.tests.test_tryton
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
from trytond.pool import Pool
from trytond.exceptions import UserWarning
from trytond.modules.company.tests import create_company, set_company
from trytond.modules.account.tests import create_chart, get_fiscalyear
from trytond.modules.account_invoice.tests import set_invoice_sequences
class SaleCreditLimitTestCase(ModuleTestCase):
'Test SaleCreditLimit module'
module = 'sale_credit_limit'
@with_transaction()
def test_check_credit_limit(self):
'Test check_credit_limit'
pool = Pool()
Account = pool.get('account.account')
Move = pool.get('account.move')
Journal = pool.get('account.journal')
Party = pool.get('party.party')
Sale = pool.get('sale.sale')
PaymentTerm = pool.get('account.invoice.payment_term')
Property = pool.get('ir.property')
ModelField = pool.get('ir.model.field')
FiscalYear = pool.get('account.fiscalyear')
company = create_company()
with set_company(company):
create_chart(company)
fiscalyear = set_invoice_sequences(get_fiscalyear(company))
fiscalyear.save()
FiscalYear.create_period([fiscalyear])
period = fiscalyear.periods[0]
receivable, = Account.search([
('kind', '=', 'receivable'),
])
revenue, = Account.search([
('kind', '=', 'revenue'),
])
journal, = Journal.search([], limit=1)
party, = Party.create([{
'name': 'Party',
'addresses': [
('create', [{}]),
],
'credit_limit_amount': Decimal('100'),
}])
Move.create([{
'journal': journal.id,
'period': period.id,
'date': period.start_date,
'lines': [
('create', [{
'debit': Decimal('100'),
'account': receivable.id,
'party': party.id,
}, {
'credit': Decimal('100'),
'account': revenue.id,
}]),
],
}])
payment_term, = PaymentTerm.create([{
'name': 'Test',
'lines': [
('create', [{
'type': 'remainder',
}])
],
}])
field, = ModelField.search([
('model.model', '=', 'product.template'),
('name', '=', 'account_revenue'),
], limit=1)
Property.create([{
'field': field.id,
'value': str(revenue),
'company': company.id,
}])
sale, = Sale.create([{
'party': party.id,
'company': company.id,
'payment_term': payment_term.id,
'currency': company.currency.id,
'invoice_address': party.addresses[0].id,
'shipment_address': party.addresses[0].id,
'lines': [
('create', [{
'description': 'Test',
'quantity': 1,
'unit_price': Decimal('50'),
}]),
],
}])
self.assertEqual(party.credit_amount, Decimal('100'))
Sale.quote([sale])
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')
self.assertEqual(party.credit_amount, Decimal('150'))
# Re-process
Sale.process([sale])
# Decrease limit
party.credit_limit_amount = Decimal('100')
party.save()
# process should still work as sale is already processing
Sale.process([sale])
def suite():
suite = trytond.tests.test_tryton.suite()
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
SaleCreditLimitTestCase))
return suite
|