def test_move_lines(self): 'Test move lines' pool = Pool() Account = pool.get('account.account') FiscalYear = pool.get('account.fiscalyear') Journal = pool.get('account.journal') Move = pool.get('account.move') MoveLine = pool.get('account.move.line') PaymentType = pool.get('account.payment.type') company = create_company() with set_company(company): create_chart(company) fiscalyear = get_fiscalyear(company) set_invoice_sequences(fiscalyear) fiscalyear.save() FiscalYear.create_period([fiscalyear]) period = fiscalyear.periods[0] journal_revenue, = Journal.search([ ('code', '=', 'REV'), ]) revenue, = Account.search([ ('type.revenue', '=', True), ]) receivable, = Account.search([ ('type.receivable', '=', True), ]) payable, = Account.search([ ('type.payable', '=', True), ]) payment_payable, = PaymentType.create([{ 'name': 'Payment Payable', 'kind': 'payable', 'company': company.id, }]) payment_receivable, = PaymentType.create([{ 'name': 'Payment Receivable', 'kind': 'receivable', 'company': company.id, }]) move, = Move.create([{ 'period': period.id, 'journal': journal_revenue.id, 'date': period.start_date, }]) MoveLine.create([{ 'move': move.id, 'account': revenue.id, 'debit': Decimal(30), }]) self.assertRaises(Exception, MoveLine.create, [{ 'move': move.id, 'account': revenue.id, 'debit': Decimal(30), 'payment_type': payment_receivable, }])
def test_invoice_generation(self): 'Test invoice generation' pool = Pool() Account = pool.get('account.account') FiscalYear = pool.get('account.fiscalyear') Invoice = pool.get('account.invoice') InvoiceLine = pool.get('account.invoice.line') Party = pool.get('party.party') PaymentTerm = pool.get('account.invoice.payment_term') ProductUom = pool.get('product.uom') ProductCategory = pool.get('product.category') ProductTemplate = pool.get('product.template') Product = pool.get('product.product') Tax = pool.get('account.tax') Address = pool.get('party.address') PartyIdentifier = pool.get('party.identifier') Country = pool.get('country.country') Subdivision = pool.get('country.subdivision') PaymentType = pool.get('account.payment.type') country = Country(name='Country', code='ES', code3='ESP') country.save() subdivision = Subdivision(name='Subdivision', country=country, code='SUB', type='province') subdivision.save() company = create_company() currency = create_currency('EUR') add_currency_rate(currency, 1.0) tax_identifier = PartyIdentifier() tax_identifier.type = 'eu_vat' tax_identifier.code = 'BE0897290877' company.header = 'Report Header' company.party.name = 'Seller' company.party.identifiers = [tax_identifier] company.party.facturae_person_type = 'J' company.party.facturae_residence_type = 'R' company.party.save() company.save() # Save certificate into company with open(os.path.join(CURRENT_PATH, 'certificate.pfx'), 'rb') as cert_file: company.facturae_certificate = cert_file.read() payment_term, = PaymentTerm.create([{ 'name': '20 days, 40 days', 'lines': [('create', [{ 'sequence': 0, 'type': 'percent', 'divisor': 2, 'ratio': Decimal('.5'), 'relativedeltas': [ ('create', [ { 'days': 20, }, ]), ], }, { 'sequence': 1, 'type': 'remainder', 'relativedeltas': [ ('create', [ { 'days': 40, }, ]), ], }])] }]) with set_company(company): create_chart(company, tax=True) fiscalyear = set_invoice_sequences(get_fiscalyear(company)) fiscalyear.save() FiscalYear.create_period([fiscalyear]) payment_receivable, = PaymentType.create([{ 'name': 'Payment Receivable', 'kind': 'receivable', 'company': company.id, 'facturae_type': '01', }]) revenue, = Account.search([('type.revenue', '=', True)]) expense, = Account.search([('type.expense', '=', True)]) tax_account, = Account.search([ ('name', '=', 'Main Tax'), ]) with Transaction().set_user(0): vat21 = Tax() vat21.name = vat21.description = '21% VAT' vat21.type = 'percentage' vat21.rate = Decimal('0.21') vat21.invoice_account = tax_account vat21.report_type = '05' vat21.credit_note_account = tax_account vat21.save() company_address, = company.party.addresses company_address.street = 'street' company_address.zip = '08201' company_address.city = 'City' company_address.subdivision = subdivision company_address.country = country company_address.save() party = Party(name='Buyer') party.facturae_person_type = 'J' party.facturae_residence_type = 'R' tax_identifier = PartyIdentifier() tax_identifier.type = 'eu_vat' tax_identifier.code = 'BE0897290877' party.identifiers = [tax_identifier] party.save() address_dict = { 'party': party.id, 'street': 'St sample, 15', 'city': 'City', 'zip': '08201', 'subdivision': subdivision.id, 'country': country.id, } address, = Address.create([address_dict]) term, = PaymentTerm.create([{ 'name': 'Payment term', 'lines': [('create', [{ 'type': 'remainder', 'relativedeltas': [('create', [{ 'sequence': 0, 'days': 0, 'months': 0, 'weeks': 0, }])], }])], }]) account_category = ProductCategory() account_category.name = 'Account Category' account_category.accounting = True account_category.account_expense = expense account_category.account_revenue = revenue account_category.customer_taxes = [vat21] account_category.save() unit, = ProductUom.search([('name', '=', 'Unit')]) template = ProductTemplate() template.name = 'product' template.default_uom = unit template.type = 'service' template.list_price = Decimal('40') template.account_category = account_category template.save() product = Product() product.template = template product.save() currency = create_currency('Eur') add_currency_rate(currency, 1) with Transaction().set_user(0): invoice = Invoice() invoice.type = 'out' invoice.on_change_type() invoice.party = party invoice.on_change_party() invoice.payment_type = payment_receivable invoice.payment_term = term invoice.currency = currency invoice.company = company invoice.payment_term = invoice.on_change_with_payment_term() invoice.account = invoice.on_change_with_account() line1 = InvoiceLine() line1.product = product line1.on_change_product() line1.on_change_account() line1.quantity = 5 line1.unit_price = Decimal('40') line2 = InvoiceLine() line2.account = revenue line2.on_change_account() line2.product = product line2.on_change_product() line2.description = 'Test' line2.quantity = 1 line2.unit_price = Decimal(20) invoice.lines = [line1, line2] invoice.on_change_lines() invoice.save() Invoice.post([invoice]) Invoice.generate_facturae_default([invoice], 'privatepassword')
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 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') Configuration = pool.get('account.configuration') FiscalYear = pool.get('account.fiscalyear') Invoice = pool.get('account.invoice') 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([ ('type.receivable', '=', True), ]) revenue, = Account.search([ ('type.revenue', '=', True), ]) 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', }])], }]) config = Configuration(1) config.default_category_account_revenue = revenue config.save() 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]) # Test limit reaches self.assertRaises(UserWarning, Sale.confirm, [sale]) self.assertEqual(party.credit_amount, Decimal('100')) # Increase limit party.credit_limit_amount = Decimal('200') party.save() # process should work Sale.confirm([sale]) self.assertEqual(sale.state, 'confirmed') self.assertEqual(party.credit_amount, Decimal('150')) # 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]) # Increase quantity invoiced does not change the credit amount invoice, = sale.invoices invoice_line, = invoice.lines invoice_line.quantity += 1 invoice_line.save() Invoice.post([invoice]) self.assertEqual(party.credit_amount, Decimal('150'))
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])