From 383441d2300f00f7f306f210e29d35e64d667916 Mon Sep 17 00:00:00 2001 From: gilles Date: Tue, 14 Mar 2017 19:09:03 +0100 Subject: [PATCH] [FIX] cleanup --- .../README.rst | 2 +- .../__manifest__.py | 8 -- .../model/account.py | 12 +- .../model/account_invoice.py | 4 +- .../test_account_constraint_chronology.py | 123 ++++++++++-------- .../view/account_view.xml | 22 ++-- 6 files changed, 88 insertions(+), 83 deletions(-) diff --git a/account_invoice_constraint_chronology/README.rst b/account_invoice_constraint_chronology/README.rst index 7ff9af8e..78fad5ac 100644 --- a/account_invoice_constraint_chronology/README.rst +++ b/account_invoice_constraint_chronology/README.rst @@ -23,7 +23,7 @@ Usage .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/92/8.0 + :target: https://runbot.odoo-community.org/runbot/92/10.0 Bug Tracker =========== diff --git a/account_invoice_constraint_chronology/__manifest__.py b/account_invoice_constraint_chronology/__manifest__.py index 2a334a8a..ebed7b86 100644 --- a/account_invoice_constraint_chronology/__manifest__.py +++ b/account_invoice_constraint_chronology/__manifest__.py @@ -10,14 +10,6 @@ "license": "AGPL-3", "category": "Accounting", "depends": ["account"], - "description": """ - Account Invoice Constraint Chronology - This module helps ensuring the chronology of invoice numbers. - It prevents the validation of invoices when: - * there are draft invoices with an anterior date - * there are validated invoices with a posterior date - """, - "test": ["../account/test/account_minimal_test.xml"], "data": ["view/account_view.xml"], 'installable': True, } diff --git a/account_invoice_constraint_chronology/model/account.py b/account_invoice_constraint_chronology/model/account.py index 3cf04a46..04bbbd18 100644 --- a/account_invoice_constraint_chronology/model/account.py +++ b/account_invoice_constraint_chronology/model/account.py @@ -5,15 +5,15 @@ from odoo import models, fields, api -class account_journal(models.Model): +class AccountJournal(models.Model): _inherit = ['account.journal'] check_chronology = fields.Boolean(string='Check Chronology', default=False) - @api.one + @api.multi @api.onchange('type') def on_change_type(self): - if self.type not in ['sale', 'purchase', 'sale_refund', - 'purchase_refund']: - self.check_chronology = False - return True + for rec in self: + if rec.type not in ['sale', 'purchase']: + rec.check_chronology = False + return True diff --git a/account_invoice_constraint_chronology/model/account_invoice.py b/account_invoice_constraint_chronology/model/account_invoice.py index b93e14af..b7bc0fd1 100644 --- a/account_invoice_constraint_chronology/model/account_invoice.py +++ b/account_invoice_constraint_chronology/model/account_invoice.py @@ -6,13 +6,13 @@ from odoo import models, api, fields, _ from odoo.exceptions import UserError -class account_invoice(models.Model): +class AccountInvoice(models.Model): _inherit = "account.invoice" @api.multi def action_move_create(self): previously_validated = self.filtered(lambda inv: inv.move_name) - res = super(account_invoice, self).action_move_create() + res = super(AccountInvoice, self).action_move_create() for inv in self: if inv.journal_id.check_chronology: invoices = \ diff --git a/account_invoice_constraint_chronology/tests/test_account_constraint_chronology.py b/account_invoice_constraint_chronology/tests/test_account_constraint_chronology.py index 1781f696..9a88bbac 100644 --- a/account_invoice_constraint_chronology/tests/test_account_constraint_chronology.py +++ b/account_invoice_constraint_chronology/tests/test_account_constraint_chronology.py @@ -8,92 +8,107 @@ from datetime import datetime, timedelta from odoo.tools import DEFAULT_SERVER_DATE_FORMAT -def get_journal_check(self, value): - 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 create_simple_invoice(self, journal_id, date): - 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.AccountJournal = self.env['account.journal'] - self.Account = self.env['account.account'] + + # Needed to create invoice + + self.account_type1 = self.env['account.account.type'].\ + create({'name': 'acc type test 1', + 'type': 'receivable', + 'include_initial_balance': True}) + self.account_type2 = self.env['account.account.type']. \ + create({'name': 'acc type test 2', + 'type': 'other', + 'include_initial_balance': True}) + self.account_account = self.env['account.account'].\ + create({'name': 'acc test', + 'code': 'X2020', + 'user_type_id': self.account_type1.id, + 'reconcile': True}) + self.account_account_line = self.env['account.account']. \ + create({'name': 'acc inv line test', + 'code': 'X2021', + 'user_type_id': self.account_type2.id, + 'reconcile': True}) + self.sequence = self.env['ir.sequence'].create( + {'name': 'Journal Sale', + 'prefix': 'SALE', 'padding': 6, + 'company_id': self.env.ref("base.main_company").id}) + self.account_journal_sale = self.env['account.journal']\ + .create({'name': 'Sale journal', + 'code': 'SALE', + 'type': 'sale', + 'sequence_id': self.sequence.id}) + self.product = self.env['product.product'].create( + {'name': 'product name'}) + self.analytic_account = self.env['account.analytic.account'].\ + create({'name': 'test account'}) + + def get_journal_check(self, value): + journal = self.account_journal_sale.copy() + journal.check_chronology = value + return journal + + def create_simple_invoice(self, journal_id, date): + invoice = self.env['account.invoice'].create( + {'partner_id': self.env.ref('base.res_partner_2').id, + 'account_id': self.account_account.id, + 'type': 'in_invoice', + 'journal_id': journal_id, + 'date_invoice': date, + 'state': 'draft', + }) + + self.env['account.invoice.line'].create( + {'product_id': self.product.id, + 'quantity': 1.0, + 'price_unit': 100.0, + 'invoice_id': invoice.id, + 'name': 'product that cost 100', + 'account_id': self.account_account_line.id, + 'account_analytic_id': self.analytic_account.id, + }) + return invoice def test_invoice_draft(self): - journal = get_journal_check(self, True) + journal = self.get_journal_check(True) today = datetime.now() yesterday = today - timedelta(days=1) date = yesterday.strftime(DEFAULT_SERVER_DATE_FORMAT) - create_simple_invoice(self, journal.id, date) + self.create_simple_invoice(journal.id, date) date = today.strftime(DEFAULT_SERVER_DATE_FORMAT) - invoice_2 = create_simple_invoice(self, journal.id, date) + invoice_2 = self.create_simple_invoice(journal.id, date) 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) + journal = self.get_journal_check(True) today = datetime.now() tomorrow = today + timedelta(days=1) date_tomorrow = tomorrow.strftime(DEFAULT_SERVER_DATE_FORMAT) - invoice_1 = create_simple_invoice(self, journal.id, date_tomorrow) + invoice_1 = self.create_simple_invoice(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) + invoice_2 = self.create_simple_invoice(journal.id, date) 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) + journal = self.get_journal_check(True) today = datetime.now() yesterday = today - timedelta(days=1) date = yesterday.strftime(DEFAULT_SERVER_DATE_FORMAT) - create_simple_invoice(self, journal.id, date) - invoice_2 = create_simple_invoice(self, journal.id, False) + self.create_simple_invoice(journal.id, date) + invoice_2 = self.create_simple_invoice(journal.id, False) self.assertTrue((invoice_2.state == 'draft'), "Initial invoice state is not Draft") with self.assertRaises(UserError): diff --git a/account_invoice_constraint_chronology/view/account_view.xml b/account_invoice_constraint_chronology/view/account_view.xml index 95baf1ee..20a236ea 100644 --- a/account_invoice_constraint_chronology/view/account_view.xml +++ b/account_invoice_constraint_chronology/view/account_view.xml @@ -2,16 +2,14 @@ - - - account.journal.form (account_constraint_chronology) - account.journal - - - - - - - - + + account.journal.form (account_constraint_chronology) + account.journal + + + + + + +