From 12ac4e1d8bd59a25ed3b841bc9b524c0e0193878 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Thu, 25 Oct 2018 15:47:09 +0200 Subject: [PATCH] [MIG] contract: Migration to 12.0 --- contract/__manifest__.py | 2 +- .../migrations/11.0.2.0.0/pre-migration.py | 18 --------- contract/models/account_analytic_contract.py | 1 + .../models/account_analytic_contract_line.py | 2 +- contract/readme/CONTRIBUTORS.rst | 1 + contract/tests/test_contract.py | 40 ++++++++++++------- .../views/account_analytic_account_view.xml | 12 +++--- .../views/account_analytic_contract_view.xml | 17 +++++--- 8 files changed, 47 insertions(+), 46 deletions(-) delete mode 100644 contract/migrations/11.0.2.0.0/pre-migration.py diff --git a/contract/__manifest__.py b/contract/__manifest__.py index f065ff52..7bdc150c 100644 --- a/contract/__manifest__.py +++ b/contract/__manifest__.py @@ -8,7 +8,7 @@ { 'name': 'Contracts Management - Recurring', - 'version': '11.0.4.0.0', + 'version': '12.0.1.0.0', 'category': 'Contract Management', 'license': 'AGPL-3', 'author': "OpenERP SA, " diff --git a/contract/migrations/11.0.2.0.0/pre-migration.py b/contract/migrations/11.0.2.0.0/pre-migration.py deleted file mode 100644 index d48abf7b..00000000 --- a/contract/migrations/11.0.2.0.0/pre-migration.py +++ /dev/null @@ -1,18 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2015-2017 Tecnativa - Pedro M. Baeza -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - - -def migrate(cr, version): - """Rename column for specific price for keeping backwards compatibility.""" - if not version: - return - cr.execute("""SELECT column_name - FROM information_schema.columns - WHERE table_name='account_analytic_invoice_line' AND - column_name='price_unit'""") - if cr.fetchone(): - cr.execute( - "ALTER TABLE account_analytic_invoice_line " - "RENAME price_unit TO specific_price" - ) diff --git a/contract/models/account_analytic_contract.py b/contract/models/account_analytic_contract.py index 162206cb..356f90a0 100644 --- a/contract/models/account_analytic_contract.py +++ b/contract/models/account_analytic_contract.py @@ -10,6 +10,7 @@ from odoo import api, fields, models class AccountAnalyticContract(models.Model): _name = 'account.analytic.contract' + _description = "Account Analytic Contract" # These fields will not be synced to the contract NO_SYNC = [ diff --git a/contract/models/account_analytic_contract_line.py b/contract/models/account_analytic_contract_line.py index 9dbb0f05..4eca3aa3 100644 --- a/contract/models/account_analytic_contract_line.py +++ b/contract/models/account_analytic_contract_line.py @@ -38,7 +38,7 @@ class AccountAnalyticContractLine(models.Model): required=True, ) uom_id = fields.Many2one( - 'product.uom', + 'uom.uom', string='Unit of Measure', required=True, ) diff --git a/contract/readme/CONTRIBUTORS.rst b/contract/readme/CONTRIBUTORS.rst index ed395a7d..820de990 100644 --- a/contract/readme/CONTRIBUTORS.rst +++ b/contract/readme/CONTRIBUTORS.rst @@ -4,3 +4,4 @@ * Dave Lasley * Vicent Cubells * Miquel Raïch +* Souheil Bejaoui diff --git a/contract/tests/test_contract.py b/contract/tests/test_contract.py index d0e48e4a..4ce51aaa 100644 --- a/contract/tests/test_contract.py +++ b/contract/tests/test_contract.py @@ -90,6 +90,7 @@ class TestContract(TestContractBase): self.assertEqual(self.acct_line.price_unit, 10) def test_contract(self): + recurring_next_date = fields.Date.to_date('2016-03-29') self.assertAlmostEqual(self.acct_line.price_subtotal, 50.0) res = self.acct_line._onchange_product_id() self.assertIn('uom_id', res['domain']) @@ -101,7 +102,8 @@ class TestContract(TestContractBase): self.invoice_monthly = self.env['account.invoice'].search( [('contract_id', '=', self.contract.id)]) self.assertTrue(self.invoice_monthly) - self.assertEqual(self.contract.recurring_next_date, '2016-03-29') + self.assertEqual(self.contract.recurring_next_date, + recurring_next_date) 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) @@ -109,6 +111,7 @@ class TestContract(TestContractBase): self.invoice_monthly.user_id) def test_contract_daily(self): + recurring_next_date = fields.Date.to_date('2016-03-01') self.contract.recurring_next_date = '2016-02-29' self.contract.recurring_rule_type = 'daily' self.contract.pricelist_id = False @@ -116,9 +119,11 @@ class TestContract(TestContractBase): invoice_daily = self.env['account.invoice'].search( [('contract_id', '=', self.contract.id)]) self.assertTrue(invoice_daily) - self.assertEqual(self.contract.recurring_next_date, '2016-03-01') + self.assertEqual(self.contract.recurring_next_date, + recurring_next_date) def test_contract_weekly(self): + recurring_next_date = fields.Date.to_date('2016-03-07') self.contract.recurring_next_date = '2016-02-29' self.contract.recurring_rule_type = 'weekly' self.contract.recurring_invoicing_type = 'post-paid' @@ -127,9 +132,10 @@ class TestContract(TestContractBase): [('contract_id', '=', self.contract.id)]) self.assertTrue(invoices_weekly) self.assertEqual( - self.contract.recurring_next_date, '2016-03-07') + self.contract.recurring_next_date, recurring_next_date) def test_contract_yearly(self): + recurring_next_date = fields.Date.to_date('2017-02-28') self.contract.recurring_next_date = '2016-02-29' self.contract.recurring_rule_type = 'yearly' self.contract.recurring_create_invoice() @@ -137,9 +143,10 @@ class TestContract(TestContractBase): [('contract_id', '=', self.contract.id)]) self.assertTrue(invoices_weekly) self.assertEqual( - self.contract.recurring_next_date, '2017-02-28') + self.contract.recurring_next_date, recurring_next_date) def test_contract_monthly_lastday(self): + recurring_next_date = fields.Date.to_date('2016-03-31') self.contract.recurring_next_date = '2016-02-29' self.contract.recurring_invoicing_type = 'post-paid' self.contract.recurring_rule_type = 'monthlylastday' @@ -147,7 +154,8 @@ class TestContract(TestContractBase): invoices_monthly_lastday = self.env['account.invoice'].search( [('contract_id', '=', self.contract.id)]) self.assertTrue(invoices_monthly_lastday) - self.assertEqual(self.contract.recurring_next_date, '2016-03-31') + self.assertEqual(self.contract.recurring_next_date, + recurring_next_date) def test_onchange_partner_id(self): self.contract._onchange_partner_id() @@ -155,13 +163,14 @@ class TestContract(TestContractBase): self.contract.partner_id.property_product_pricelist) def test_onchange_date_start(self): - date = '2016-01-01' - self.contract.date_start = date + recurring_next_date = fields.Date.to_date('2016-01-01') + self.contract.date_start = recurring_next_date self.contract._onchange_date_start() - self.assertEqual(self.contract.recurring_next_date, date) + self.assertEqual(self.contract.recurring_next_date, + recurring_next_date) def test_uom(self): - uom_litre = self.env.ref('product.product_uom_litre') + uom_litre = self.env.ref('uom.product_uom_litre') self.acct_line.uom_id = uom_litre.id self.acct_line._onchange_product_id() self.assertEqual(self.acct_line.uom_id, @@ -273,9 +282,9 @@ class TestContract(TestContractBase): def test_contract_onchange_product_id_uom(self): """It should update the UoM for the line.""" line = self._add_template_line( - {'uom_id': self.env.ref('product.product_uom_litre').id} + {'uom_id': self.env.ref('uom.product_uom_litre').id} ) - line.product_id.uom_id = self.env.ref('product.product_uom_day').id + line.product_id.uom_id = self.env.ref('uom.product_uom_day').id line._onchange_product_id() self.assertEqual(line.uom_id, line.product_id.uom_id) @@ -292,13 +301,14 @@ class TestContract(TestContractBase): def test_contract_count(self): """It should return sale contract count.""" - count = self.partner.sale_contract_count + 2 + sale_count = self.partner.sale_contract_count + 2 self.contract.copy() self.contract.copy() - self.assertEqual(self.partner.sale_contract_count, count) - count = self.partner.purchase_contract_count + 1 + purchase_count = self.partner.purchase_contract_count + 1 self.contract2.copy() - self.assertEqual(self.partner.purchase_contract_count, count) + self.partner.refresh() + self.assertEqual(self.partner.sale_contract_count, sale_count) + self.assertEqual(self.partner.purchase_contract_count, purchase_count) def test_same_date_start_and_date_end(self): """It should create one invoice with same start and end date.""" diff --git a/contract/views/account_analytic_account_view.xml b/contract/views/account_analytic_account_view.xml index 1db6df28..128f1886 100644 --- a/contract/views/account_analytic_account_view.xml +++ b/contract/views/account_analytic_account_view.xml @@ -84,7 +84,7 @@ - + @@ -188,11 +188,13 @@ domain="[('date_end', '<', time.strftime('%Y-%m-%d'))]" /> - - @@ -232,7 +234,7 @@ @@ -268,7 +270,7 @@ diff --git a/contract/views/account_analytic_contract_view.xml b/contract/views/account_analytic_contract_view.xml index 8f91a23b..47f1f581 100644 --- a/contract/views/account_analytic_contract_view.xml +++ b/contract/views/account_analytic_contract_view.xml @@ -42,7 +42,7 @@ - + @@ -84,19 +84,24 @@ - - - - -