Browse Source

[MIG] contract: Migration to 12.0

pull/202/head
sbejaoui 6 years ago
committed by Pedro M. Baeza
parent
commit
12ac4e1d8b
  1. 2
      contract/__manifest__.py
  2. 18
      contract/migrations/11.0.2.0.0/pre-migration.py
  3. 1
      contract/models/account_analytic_contract.py
  4. 2
      contract/models/account_analytic_contract_line.py
  5. 1
      contract/readme/CONTRIBUTORS.rst
  6. 40
      contract/tests/test_contract.py
  7. 12
      contract/views/account_analytic_account_view.xml
  8. 17
      contract/views/account_analytic_contract_view.xml

2
contract/__manifest__.py

@ -8,7 +8,7 @@
{ {
'name': 'Contracts Management - Recurring', 'name': 'Contracts Management - Recurring',
'version': '11.0.4.0.0',
'version': '12.0.1.0.0',
'category': 'Contract Management', 'category': 'Contract Management',
'license': 'AGPL-3', 'license': 'AGPL-3',
'author': "OpenERP SA, " 'author': "OpenERP SA, "

18
contract/migrations/11.0.2.0.0/pre-migration.py

@ -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"
)

1
contract/models/account_analytic_contract.py

@ -10,6 +10,7 @@ from odoo import api, fields, models
class AccountAnalyticContract(models.Model): class AccountAnalyticContract(models.Model):
_name = 'account.analytic.contract' _name = 'account.analytic.contract'
_description = "Account Analytic Contract"
# These fields will not be synced to the contract # These fields will not be synced to the contract
NO_SYNC = [ NO_SYNC = [

2
contract/models/account_analytic_contract_line.py

@ -38,7 +38,7 @@ class AccountAnalyticContractLine(models.Model):
required=True, required=True,
) )
uom_id = fields.Many2one( uom_id = fields.Many2one(
'product.uom',
'uom.uom',
string='Unit of Measure', string='Unit of Measure',
required=True, required=True,
) )

1
contract/readme/CONTRIBUTORS.rst

@ -4,3 +4,4 @@
* Dave Lasley <dave@laslabs.com> * Dave Lasley <dave@laslabs.com>
* Vicent Cubells <vicent.cubells@tecnativa.com> * Vicent Cubells <vicent.cubells@tecnativa.com>
* Miquel Raïch <miquel.raich@eficent.com> * Miquel Raïch <miquel.raich@eficent.com>
* Souheil Bejaoui <souheil.bejaoui@acsone.eu>

40
contract/tests/test_contract.py

@ -90,6 +90,7 @@ class TestContract(TestContractBase):
self.assertEqual(self.acct_line.price_unit, 10) self.assertEqual(self.acct_line.price_unit, 10)
def test_contract(self): def test_contract(self):
recurring_next_date = fields.Date.to_date('2016-03-29')
self.assertAlmostEqual(self.acct_line.price_subtotal, 50.0) self.assertAlmostEqual(self.acct_line.price_subtotal, 50.0)
res = self.acct_line._onchange_product_id() res = self.acct_line._onchange_product_id()
self.assertIn('uom_id', res['domain']) self.assertIn('uom_id', res['domain'])
@ -101,7 +102,8 @@ class TestContract(TestContractBase):
self.invoice_monthly = self.env['account.invoice'].search( self.invoice_monthly = self.env['account.invoice'].search(
[('contract_id', '=', self.contract.id)]) [('contract_id', '=', self.contract.id)])
self.assertTrue(self.invoice_monthly) 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.inv_line = self.invoice_monthly.invoice_line_ids[0]
self.assertTrue(self.inv_line.invoice_line_tax_ids) self.assertTrue(self.inv_line.invoice_line_tax_ids)
self.assertAlmostEqual(self.inv_line.price_subtotal, 50.0) self.assertAlmostEqual(self.inv_line.price_subtotal, 50.0)
@ -109,6 +111,7 @@ class TestContract(TestContractBase):
self.invoice_monthly.user_id) self.invoice_monthly.user_id)
def test_contract_daily(self): 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_next_date = '2016-02-29'
self.contract.recurring_rule_type = 'daily' self.contract.recurring_rule_type = 'daily'
self.contract.pricelist_id = False self.contract.pricelist_id = False
@ -116,9 +119,11 @@ class TestContract(TestContractBase):
invoice_daily = self.env['account.invoice'].search( invoice_daily = self.env['account.invoice'].search(
[('contract_id', '=', self.contract.id)]) [('contract_id', '=', self.contract.id)])
self.assertTrue(invoice_daily) 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): 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_next_date = '2016-02-29'
self.contract.recurring_rule_type = 'weekly' self.contract.recurring_rule_type = 'weekly'
self.contract.recurring_invoicing_type = 'post-paid' self.contract.recurring_invoicing_type = 'post-paid'
@ -127,9 +132,10 @@ class TestContract(TestContractBase):
[('contract_id', '=', self.contract.id)]) [('contract_id', '=', self.contract.id)])
self.assertTrue(invoices_weekly) self.assertTrue(invoices_weekly)
self.assertEqual( self.assertEqual(
self.contract.recurring_next_date, '2016-03-07')
self.contract.recurring_next_date, recurring_next_date)
def test_contract_yearly(self): 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_next_date = '2016-02-29'
self.contract.recurring_rule_type = 'yearly' self.contract.recurring_rule_type = 'yearly'
self.contract.recurring_create_invoice() self.contract.recurring_create_invoice()
@ -137,9 +143,10 @@ class TestContract(TestContractBase):
[('contract_id', '=', self.contract.id)]) [('contract_id', '=', self.contract.id)])
self.assertTrue(invoices_weekly) self.assertTrue(invoices_weekly)
self.assertEqual( self.assertEqual(
self.contract.recurring_next_date, '2017-02-28')
self.contract.recurring_next_date, recurring_next_date)
def test_contract_monthly_lastday(self): 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_next_date = '2016-02-29'
self.contract.recurring_invoicing_type = 'post-paid' self.contract.recurring_invoicing_type = 'post-paid'
self.contract.recurring_rule_type = 'monthlylastday' self.contract.recurring_rule_type = 'monthlylastday'
@ -147,7 +154,8 @@ class TestContract(TestContractBase):
invoices_monthly_lastday = self.env['account.invoice'].search( invoices_monthly_lastday = self.env['account.invoice'].search(
[('contract_id', '=', self.contract.id)]) [('contract_id', '=', self.contract.id)])
self.assertTrue(invoices_monthly_lastday) 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): def test_onchange_partner_id(self):
self.contract._onchange_partner_id() self.contract._onchange_partner_id()
@ -155,13 +163,14 @@ class TestContract(TestContractBase):
self.contract.partner_id.property_product_pricelist) self.contract.partner_id.property_product_pricelist)
def test_onchange_date_start(self): 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.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): 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.uom_id = uom_litre.id
self.acct_line._onchange_product_id() self.acct_line._onchange_product_id()
self.assertEqual(self.acct_line.uom_id, self.assertEqual(self.acct_line.uom_id,
@ -273,9 +282,9 @@ class TestContract(TestContractBase):
def test_contract_onchange_product_id_uom(self): def test_contract_onchange_product_id_uom(self):
"""It should update the UoM for the line.""" """It should update the UoM for the line."""
line = self._add_template_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() line._onchange_product_id()
self.assertEqual(line.uom_id, self.assertEqual(line.uom_id,
line.product_id.uom_id) line.product_id.uom_id)
@ -292,13 +301,14 @@ class TestContract(TestContractBase):
def test_contract_count(self): def test_contract_count(self):
"""It should return sale contract count.""" """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.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.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): def test_same_date_start_and_date_end(self):
"""It should create one invoice with same start and end date.""" """It should create one invoice with same start and end date."""

12
contract/views/account_analytic_account_view.xml

@ -84,7 +84,7 @@
<field name="automatic_price"/> <field name="automatic_price"/>
<field name="price_unit" attrs="{'readonly': [('automatic_price', '=', True)]}"/> <field name="price_unit" attrs="{'readonly': [('automatic_price', '=', True)]}"/>
<field name="specific_price" invisible="1"/> <field name="specific_price" invisible="1"/>
<field name="discount" groups="sale.group_discount_per_so_line" />
<field name="discount" groups="base.group_no_one" />
<field name="price_subtotal"/> <field name="price_subtotal"/>
</tree> </tree>
</field> </field>
@ -188,11 +188,13 @@
domain="[('date_end', '&lt;', time.strftime('%Y-%m-%d'))]" domain="[('date_end', '&lt;', time.strftime('%Y-%m-%d'))]"
/> />
<group expand="0" string="Group By..."> <group expand="0" string="Group By...">
<filter string="Next Invoice"
<filter name="next_invoice"
string="Next Invoice"
domain="[]" domain="[]"
context="{'group_by':'recurring_next_date'}" context="{'group_by':'recurring_next_date'}"
/> />
<filter string="Date End"
<filter name="date_end"
string="Date End"
domain="[]" domain="[]"
context="{'group_by':'date_end'}" context="{'group_by':'date_end'}"
/> />
@ -232,7 +234,7 @@
</record> </record>
<menuitem id="menu_action_account_analytic_sale_overdue_all" <menuitem id="menu_action_account_analytic_sale_overdue_all"
parent="account.menu_finance_receivables_documents"
parent="account.menu_finance_receivables"
action="action_account_analytic_sale_overdue_all" action="action_account_analytic_sale_overdue_all"
sequence="99" sequence="99"
/> />
@ -268,7 +270,7 @@
</record> </record>
<menuitem id="menu_action_account_analytic_purchase_overdue_all" <menuitem id="menu_action_account_analytic_purchase_overdue_all"
parent="account.menu_finance_payables_documents"
parent="account.menu_finance_payables"
action="action_account_analytic_purchase_overdue_all" action="action_account_analytic_purchase_overdue_all"
sequence="99" sequence="99"
/> />

17
contract/views/account_analytic_contract_view.xml

@ -42,7 +42,7 @@
<field name="automatic_price" attrs="{'column_invisible': [('parent.contract_type','=','purchase')]}"/> <field name="automatic_price" attrs="{'column_invisible': [('parent.contract_type','=','purchase')]}"/>
<field name="price_unit" attrs="{'readonly': [('automatic_price', '=', True)]}"/> <field name="price_unit" attrs="{'readonly': [('automatic_price', '=', True)]}"/>
<field name="specific_price" invisible="1"/> <field name="specific_price" invisible="1"/>
<field name="discount" groups="sale.group_discount_per_so_line" />
<field name="discount" groups="base.group_no_one" />
<field name="price_subtotal" /> <field name="price_subtotal" />
</tree> </tree>
</field> </field>
@ -84,19 +84,24 @@
<field name="recurring_invoicing_type" /> <field name="recurring_invoicing_type" />
<field name="pricelist_id" /> <field name="pricelist_id" />
<field name="journal_id" /> <field name="journal_id" />
<filter string="Contract Type"
<filter name="contract_type"
string="Contract Type"
context="{'group_by': 'contract_type'}" context="{'group_by': 'contract_type'}"
/> />
<filter string="Recurrence"
<filter name="recurring_rule_type"
string="Recurrence"
context="{'group_by': 'recurring_rule_type'}" context="{'group_by': 'recurring_rule_type'}"
/> />
<filter string="Invoicing type"
<filter name="recurring_invoicing_type"
string="Invoicing type"
context="{'group_by': 'recurring_invoicing_type'}" context="{'group_by': 'recurring_invoicing_type'}"
/> />
<filter string="Pricelist"
<filter name="pricelist_id"
string="Pricelist"
context="{'group_by': 'pricelist_id'}" context="{'group_by': 'pricelist_id'}"
/> />
<filter string="Journal"
<filter name="journal_id"
string="Journal"
context="{'group_by': 'journal_id'}" context="{'group_by': 'journal_id'}"
/> />
</search> </search>

Loading…
Cancel
Save