mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[MIG] account_invoice_constraint_chronology
This commit is contained in:
@@ -1,90 +1,62 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
#
|
||||
# Authors: Adrien Peiffer
|
||||
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
|
||||
# All Rights Reserved
|
||||
#
|
||||
# WARNING: This program as such is intended to be used by professional
|
||||
# programmers who take the whole responsibility of assessing all potential
|
||||
# consequences resulting from its eventual inadequacies and bugs.
|
||||
# End users who are looking for a ready-to-use solution with commercial
|
||||
# guarantees and support are strongly advised to contact a Free Software
|
||||
# Service Company.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#
|
||||
# Copyright 2015-2017 ACSONE SA/NV (<http://acsone.eu>)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
import openerp.tests.common as common
|
||||
from openerp import workflow
|
||||
from openerp import exceptions
|
||||
import odoo.tests.common as common
|
||||
from odoo.exceptions import UserError
|
||||
from datetime import datetime, timedelta
|
||||
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT
|
||||
|
||||
|
||||
def get_simple_product_id(self):
|
||||
return self.env['product.product'].create({'name': 'product_test_01',
|
||||
'lst_price': 2000.00,
|
||||
})
|
||||
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT
|
||||
|
||||
|
||||
def get_journal_check(self, value):
|
||||
sale_journal_id = self.ref('account.sales_journal')
|
||||
sale_journal = self.env['account.journal'].browse([sale_journal_id])
|
||||
journal = sale_journal.copy()
|
||||
sale_journal_obj = self.AccountJournal.env['account.journal'].\
|
||||
search([('type', '=', 'sale')], limit=1)
|
||||
journal = sale_journal_obj.copy()
|
||||
journal.check_chronology = value
|
||||
return journal
|
||||
|
||||
|
||||
def get_simple_account_invoice_line_values(self, product_id):
|
||||
return {'name': 'test',
|
||||
'account_id': self.ref('account.a_sale'),
|
||||
'price_unit': 2000.00,
|
||||
'quantity': 1,
|
||||
'product_id': product_id,
|
||||
}
|
||||
|
||||
|
||||
def create_simple_invoice(self, journal_id, date):
|
||||
partner_id = self.ref('base.res_partner_2')
|
||||
product = get_simple_product_id(self)
|
||||
return self.env['account.invoice']\
|
||||
.create({'partner_id': partner_id,
|
||||
'account_id':
|
||||
self.ref('account.a_recv'),
|
||||
'journal_id':
|
||||
journal_id,
|
||||
'date_invoice': date,
|
||||
'invoice_line': [(0, 0, {'name': 'test',
|
||||
'account_id':
|
||||
self.ref('account.a_sale'),
|
||||
'price_unit': 2000.00,
|
||||
'quantity': 1,
|
||||
'product_id': product.id,
|
||||
}
|
||||
)
|
||||
],
|
||||
})
|
||||
invoice_account = self.env['account.account'].\
|
||||
search([('user_type_id', '=',
|
||||
self.env.ref(
|
||||
'account.data_account_type_receivable'
|
||||
).id)], limit=1).id
|
||||
invoice_line_account = self.env['account.account'].\
|
||||
search([('user_type_id', '=',
|
||||
self.env.ref(
|
||||
'account.data_account_type_expenses'
|
||||
).id)], limit=1).id
|
||||
analytic_account = self.env['account.analytic.account'].\
|
||||
create({'name': 'test account'})
|
||||
|
||||
invoice = self.env['account.invoice'].create(
|
||||
{'partner_id': self.env.ref('base.res_partner_2').id,
|
||||
'account_id': invoice_account,
|
||||
'type': 'in_invoice',
|
||||
'journal_id': journal_id,
|
||||
'date_invoice': date,
|
||||
'state': 'draft',
|
||||
})
|
||||
# invoice.write({'internal_number': invoice.number})
|
||||
self.env['account.invoice.line'].create(
|
||||
{'product_id': self.env.ref('product.product_product_4').id,
|
||||
'quantity': 1.0,
|
||||
'price_unit': 100.0,
|
||||
'invoice_id': invoice.id,
|
||||
'name': 'product that cost 100',
|
||||
'account_id': invoice_line_account,
|
||||
'account_analytic_id': analytic_account.id,
|
||||
})
|
||||
return invoice
|
||||
|
||||
|
||||
class TestAccountConstraintChronology(common.TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestAccountConstraintChronology, self).setUp()
|
||||
self.context = self.registry("res.users").context_get(self.cr,
|
||||
self.uid)
|
||||
self.AccountJournal = self.env['account.journal']
|
||||
self.Account = self.env['account.account']
|
||||
|
||||
def test_invoice_draft(self):
|
||||
journal = get_journal_check(self, True)
|
||||
@@ -94,23 +66,26 @@ class TestAccountConstraintChronology(common.TransactionCase):
|
||||
create_simple_invoice(self, journal.id, date)
|
||||
date = today.strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||
invoice_2 = create_simple_invoice(self, journal.id, date)
|
||||
self.assertRaises(exceptions.Warning, workflow.trg_validate, self.uid,
|
||||
'account.invoice', invoice_2.id, 'invoice_open',
|
||||
self.cr)
|
||||
self.assertTrue((invoice_2.state == 'draft'),
|
||||
"Initial invoice state is not Draft")
|
||||
with self.assertRaises(UserError):
|
||||
invoice_2.action_invoice_open()
|
||||
|
||||
def test_invoice_validate(self):
|
||||
journal = get_journal_check(self, True)
|
||||
today = datetime.now()
|
||||
tomorrow = today + timedelta(days=1)
|
||||
date = tomorrow.strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||
invoice = create_simple_invoice(self, journal.id, date)
|
||||
workflow.trg_validate(self.uid, 'account.invoice', invoice.id,
|
||||
'invoice_open', self.cr)
|
||||
date_tomorrow = tomorrow.strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||
invoice_1 = create_simple_invoice(self, journal.id, date_tomorrow)
|
||||
self.assertTrue((invoice_1.state == 'draft'),
|
||||
"Initial invoice state is not Draft")
|
||||
invoice_1.action_invoice_open()
|
||||
date = today.strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||
invoice_2 = create_simple_invoice(self, journal.id, date)
|
||||
self.assertRaises(exceptions.Warning, workflow.trg_validate, self.uid,
|
||||
'account.invoice', invoice_2.id, 'invoice_open',
|
||||
self.cr)
|
||||
self.assertTrue((invoice_2.state == 'draft'),
|
||||
"Initial invoice state is not Draft")
|
||||
with self.assertRaises(UserError):
|
||||
invoice_2.action_invoice_open()
|
||||
|
||||
def test_invoice_without_date(self):
|
||||
journal = get_journal_check(self, True)
|
||||
@@ -119,6 +94,7 @@ class TestAccountConstraintChronology(common.TransactionCase):
|
||||
date = yesterday.strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||
create_simple_invoice(self, journal.id, date)
|
||||
invoice_2 = create_simple_invoice(self, journal.id, False)
|
||||
self.assertRaises(exceptions.Warning, workflow.trg_validate, self.uid,
|
||||
'account.invoice', invoice_2.id, 'invoice_open',
|
||||
self.cr)
|
||||
self.assertTrue((invoice_2.state == 'draft'),
|
||||
"Initial invoice state is not Draft")
|
||||
with self.assertRaises(UserError):
|
||||
invoice_2.action_invoice_open()
|
||||
|
||||
Reference in New Issue
Block a user