From 37d2f3d6110d41bf04fa1ec17fb9c6d48599b26d Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Thu, 6 Oct 2016 14:50:37 +0200 Subject: [PATCH] [MIG] contract: Migration to version 10.0 --- contract/README.rst | 10 +- contract/{__openerp__.py => __manifest__.py} | 4 +- contract/data/contract_cron.xml | 24 +-- contract/models/contract.py | 17 +- contract/models/invoice.py | 2 +- contract/security/ir.model.access.csv | 4 +- contract/tests/test_contract.py | 7 +- contract/views/account_invoice_view.xml | 28 ++- contract/views/contract.xml | 208 +++++++++---------- 9 files changed, 151 insertions(+), 153 deletions(-) rename contract/{__openerp__.py => __manifest__.py} (88%) diff --git a/contract/README.rst b/contract/README.rst index fc7edb7d..c073600c 100644 --- a/contract/README.rst +++ b/contract/README.rst @@ -6,8 +6,9 @@ Contracts for recurrent invoicing ================================= -This module forward-port to v9 the contracts management with recurring -invoicing functions. +This module forward-port to v10 the contracts management with recurring +invoicing functions. In upstream Odoo, this functionality was moved into the +Enterprise edition. Configuration ============= @@ -19,9 +20,10 @@ Usage To use this module, you need to: -#. Go to Sales -> Contracts and select or create a new contract. +#. Go to Accounting -> Contracts and select or create a new contract. #. Check *Generate recurring invoices automatically*. #. Fill fields for selecting the recurrency and invoice parameters: + * Journal * Pricelist * Period. It can be any interval of days, weeks, months, months last day or @@ -41,7 +43,7 @@ To use this module, you need to: .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/110/9.0 + :target: https://runbot.odoo-community.org/runbot/110/10.0 Known issues / Roadmap ====================== diff --git a/contract/__openerp__.py b/contract/__manifest__.py similarity index 88% rename from contract/__openerp__.py rename to contract/__manifest__.py index c64a0d98..173be551 100644 --- a/contract/__openerp__.py +++ b/contract/__manifest__.py @@ -5,13 +5,13 @@ { 'name': 'Contracts Management recurring', - 'version': '9.0.1.1.0', + 'version': '10.0.1.0.0', 'category': 'Contract Management', 'license': 'AGPL-3', 'author': "OpenERP SA," "Tecnativa," "Odoo Community Association (OCA)", - 'website': 'http://openerp.com', + 'website': 'https://github.com/oca/contract', 'depends': ['base', 'account', 'analytic'], 'data': [ 'security/ir.model.access.csv', diff --git a/contract/data/contract_cron.xml b/contract/data/contract_cron.xml index 26442c0d..7c3a1fef 100644 --- a/contract/data/contract_cron.xml +++ b/contract/data/contract_cron.xml @@ -1,16 +1,14 @@ - - + - - Generate Recurring Invoices from Contracts - 1 - days - -1 - - - - + + Generate Recurring Invoices from Contracts + 1 + days + -1 + + + + - - + diff --git a/contract/models/contract.py b/contract/models/contract.py index ebd61df6..89bd5fbe 100644 --- a/contract/models/contract.py +++ b/contract/models/contract.py @@ -8,10 +8,10 @@ from dateutil.relativedelta import relativedelta import logging -from openerp import api, fields, models -from openerp.addons.decimal_precision import decimal_precision as dp -from openerp.exceptions import ValidationError -from openerp.tools.translate import _ +from odoo import api, fields, models +from odoo.addons import decimal_precision as dp +from odoo.exceptions import ValidationError +from odoo.tools.translate import _ _logger = logging.getLogger(__name__) @@ -30,7 +30,7 @@ class AccountAnalyticInvoiceLine(models.Model): price_unit = fields.Float('Unit Price', required=True) price_subtotal = fields.Float( compute='_compute_price_subtotal', - digits_compute=dp.get_precision('Account'), + digits=dp.get_precision('Account'), string='Sub Total') discount = fields.Float( string='Discount (%)', @@ -155,7 +155,7 @@ class AccountAnalyticAccount(models.Model): self.recurring_next_date = self.date_start @api.model - def get_relalive_delta(self, recurring_rule_type, interval): + def get_relative_delta(self, recurring_rule_type, interval): if recurring_rule_type == 'daily': return relativedelta(days=interval) elif recurring_rule_type == 'weekly': @@ -175,7 +175,7 @@ class AccountAnalyticAccount(models.Model): date_to = next_date - relativedelta(days=1) else: date_from = (date_start - - self.get_relalive_delta(contract.recurring_rule_type, + self.get_relative_delta(contract.recurring_rule_type, contract.recurring_interval) + relativedelta(days=1)) date_to = date_start @@ -267,7 +267,7 @@ class AccountAnalyticAccount(models.Model): for contract in self: old_date = fields.Date.from_string( contract.recurring_next_date or fields.Date.today()) - new_date = old_date + self.get_relalive_delta( + new_date = old_date + self.get_relative_delta( contract.recurring_rule_type, contract.recurring_interval) ctx = self.env.context.copy() ctx.update({ @@ -287,6 +287,5 @@ class AccountAnalyticAccount(models.Model): def cron_recurring_create_invoice(self): contracts = self.search( [('recurring_next_date', '<=', fields.date.today()), - ('account_type', '=', 'normal'), ('recurring_invoices', '=', True)]) return contracts.recurring_create_invoice() diff --git a/contract/models/invoice.py b/contract/models/invoice.py index 8761dfa3..f93c1127 100644 --- a/contract/models/invoice.py +++ b/contract/models/invoice.py @@ -2,7 +2,7 @@ # © 2016 Carlos Dauden # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from openerp import fields, models +from odoo import fields, models class AccountInvoice(models.Model): diff --git a/contract/security/ir.model.access.csv b/contract/security/ir.model.access.csv index 902c5d59..d477bb78 100644 --- a/contract/security/ir.model.access.csv +++ b/contract/security/ir.model.access.csv @@ -1,4 +1,4 @@ "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" -"account_analytic_invoice_line_manager","Recurring manager","model_account_analytic_invoice_line","base.group_sale_manager",1,1,1,1 -"account_analytic_invoice_line_user","Recurring user","model_account_analytic_invoice_line","base.group_sale_salesman",1,0,0,0 +"account_analytic_invoice_line_manager","Recurring manager","model_account_analytic_invoice_line","account.group_account_manager",1,1,1,1 +"account_analytic_invoice_line_user","Recurring user","model_account_analytic_invoice_line","account.group_account_user",1,0,0,0 diff --git a/contract/tests/test_contract.py b/contract/tests/test_contract.py index a04b8511..be2d17e6 100644 --- a/contract/tests/test_contract.py +++ b/contract/tests/test_contract.py @@ -2,8 +2,8 @@ # © 2016 Carlos Dauden # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from openerp.exceptions import ValidationError -from openerp.tests.common import TransactionCase +from odoo.exceptions import ValidationError +from odoo.tests.common import TransactionCase class TestContract(TransactionCase): @@ -12,6 +12,8 @@ class TestContract(TransactionCase): super(TestContract, self).setUp() self.partner = self.env.ref('base.res_partner_2') self.product = self.env.ref('product.product_product_2') + self.product.taxes_id += self.env['account.tax'].search( + [('type_tax_use', '=', 'sale')], limit=1) self.product.description_sale = 'Test description sale' self.contract = self.env['account.analytic.account'].create({ 'name': 'Test Contract', @@ -53,6 +55,7 @@ class TestContract(TransactionCase): self.assertEqual(self.contract.recurring_next_date, '2016-03-29') self.inv_line = self.invoice_monthly.invoice_line_ids[0] + self.assertTrue(self.inv_line.invoice_line_tax_ids) self.assertAlmostEqual(self.inv_line.price_subtotal, 50.0) self.assertEqual(self.contract.partner_id.user_id, self.invoice_monthly.user_id) diff --git a/contract/views/account_invoice_view.xml b/contract/views/account_invoice_view.xml index 09752e9f..9506a2f4 100644 --- a/contract/views/account_invoice_view.xml +++ b/contract/views/account_invoice_view.xml @@ -1,19 +1,17 @@ - - + - - - account.invoice.select.contract - account.invoice - - - - - - + + + account.invoice.select.contract + account.invoice + + + + + - + + - - + diff --git a/contract/views/contract.xml b/contract/views/contract.xml index 93b2f6b6..d9360d58 100644 --- a/contract/views/contract.xml +++ b/contract/views/contract.xml @@ -1,116 +1,114 @@ - - + - - {'search_default_contract_id': - [active_id], - 'default_contract_id': active_id} - - Invoices - account.invoice - - - + + {'search_default_contract_id': + [active_id], + 'default_contract_id': active_id} + + Invoices + account.invoice + + + - - account.analytic.account.invoice.recurring.form.inherit - account.analytic.account - - - - - + + account.analytic.account.invoice.recurring.form.inherit + account.analytic.account + + + + + +
+ +
+ + + +
-
-
+ + + + + + - - - account.analytic.account.journal.list - account.analytic.account - - - - - + + + account.analytic.account.journal.list + account.analytic.account + + + + - + + - - - account.analytic.account.contract.search - account.analytic.account - - - - - - - - - - + + + account.analytic.account.contract.search + account.analytic.account + + + + + + + + + - + + - - - Contracts - account.analytic.account - form - tree,form - {'search_default_active':1, 'search_default_recurring_invoices':1} - - -

- Click to create a new contract. -

-
-
- + + + Contracts + account.analytic.account + form + tree,form + {'search_default_active':1, 'search_default_recurring_invoices':1} + + +

+ Click to create a new contract. +

+
+
+ -
-
+