Browse Source

[FIX] contract: fix views assignment + improvement on tests + copyright in headers

**Be totally deterministic about which views to use**

Having a primary view that is not explicitly declared to be uses and w/o priority
makes Odoo to choose between one of them randomly (well, not exactly, but kind of),
so we put here which views to use.

I have also put tree view as primary and put a large priority for not being
selected on other actions that don't have this explicit views.

A friendly name in views is also assigned.

**Improvements in tests**

* Use SavepointCase for making the setup only once for all tests
* Make them inheritable, creating a base class with only the setup,
  so that it can be inherited without the need of executing all tests
  contained here each time you inherit it, and adding other class
  in the same module that inherits from the base class that actually
  performs the tests.
* Removed duplicated test method
13.0-mig-contract
Pedro M. Baeza 7 years ago
committed by Administrator
parent
commit
032890d8e4
  1. 10
      contract/__manifest__.py
  2. 70
      contract/tests/test_contract.py
  3. 23
      contract/views/account_analytic_account_view.xml

10
contract/__manifest__.py

@ -1,11 +1,15 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# © 2004-2010 OpenERP SA
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# Copyright 2004-2010 OpenERP SA
# Copyright 2014-2017 Tecnativa - Pedro M. Baeza
# Copyright 2015 Domatix
# Copyright 2016 Tecnativa - Carlos Dauden
# Copyright 2017 Tecnativa - Vicent Cubells
# Copyright 2016-2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{ {
'name': 'Contracts Management - Recurring', 'name': 'Contracts Management - Recurring',
'version': '10.0.2.0.0',
'version': '10.0.2.1.0',
'category': 'Contract Management', 'category': 'Contract Management',
'license': 'AGPL-3', 'license': 'AGPL-3',
'author': "OpenERP SA, " 'author': "OpenERP SA, "

70
contract/tests/test_contract.py

@ -1,49 +1,52 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# Copyright 2016 Tecnativa - Carlos Dauden
# Copyright 2017 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError
from odoo.tests.common import TransactionCase
from odoo.tests import common
class TestContract(TransactionCase):
# Use case : Prepare some data for current test case
def setUp(self):
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(
class TestContractBase(common.SavepointCase):
@classmethod
def setUpClass(cls):
super(TestContractBase, cls).setUpClass()
cls.partner = cls.env.ref('base.res_partner_2')
cls.product = cls.env.ref('product.product_product_2')
cls.product.taxes_id += cls.env['account.tax'].search(
[('type_tax_use', '=', 'sale')], limit=1) [('type_tax_use', '=', 'sale')], limit=1)
self.product.description_sale = 'Test description sale'
self.template_vals = {
cls.product.description_sale = 'Test description sale'
cls.template_vals = {
'recurring_rule_type': 'yearly', 'recurring_rule_type': 'yearly',
'recurring_interval': 12345, 'recurring_interval': 12345,
'name': 'Test Contract Template', 'name': 'Test Contract Template',
} }
self.template = self.env['account.analytic.contract'].create(
self.template_vals,
cls.template = cls.env['account.analytic.contract'].create(
cls.template_vals,
) )
self.contract = self.env['account.analytic.account'].create({
cls.contract = cls.env['account.analytic.account'].create({
'name': 'Test Contract', 'name': 'Test Contract',
'partner_id': self.partner.id,
'pricelist_id': self.partner.property_product_pricelist.id,
'partner_id': cls.partner.id,
'pricelist_id': cls.partner.property_product_pricelist.id,
'recurring_invoices': True, 'recurring_invoices': True,
'date_start': '2016-02-15', 'date_start': '2016-02-15',
'recurring_next_date': '2016-02-29', 'recurring_next_date': '2016-02-29',
}) })
self.line_vals = {
'analytic_account_id': self.contract.id,
'product_id': self.product.id,
cls.line_vals = {
'analytic_account_id': cls.contract.id,
'product_id': cls.product.id,
'name': 'Services from #START# to #END#', 'name': 'Services from #START# to #END#',
'quantity': 1, 'quantity': 1,
'uom_id': self.product.uom_id.id,
'uom_id': cls.product.uom_id.id,
'price_unit': 100, 'price_unit': 100,
'discount': 50, 'discount': 50,
} }
self.acct_line = self.env['account.analytic.invoice.line'].create(
self.line_vals,
cls.acct_line = cls.env['account.analytic.invoice.line'].create(
cls.line_vals,
) )
class TestContract(TestContractBase):
def _add_template_line(self, overrides=None): def _add_template_line(self, overrides=None):
if overrides is None: if overrides is None:
overrides = {} overrides = {}
@ -229,26 +232,3 @@ class TestContract(TransactionCase):
'\n'.join([line.product_id.name, '\n'.join([line.product_id.name,
line.product_id.description_sale, line.product_id.description_sale,
])) ]))
def test_contract(self):
self.assertAlmostEqual(self.acct_line.price_subtotal, 50.0)
res = self.acct_line._onchange_product_id()
self.assertIn('uom_id', res['domain'])
self.acct_line.price_unit = 100.0
self.contract.partner_id = False
with self.assertRaises(ValidationError):
self.contract.recurring_create_invoice()
self.contract.partner_id = self.partner.id
self.contract.recurring_create_invoice()
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.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)

23
contract/views/account_analytic_account_view.xml

@ -2,10 +2,11 @@
<odoo> <odoo>
<record id="account_analytic_account_recurring_form_form" model="ir.ui.view"> <record id="account_analytic_account_recurring_form_form" model="ir.ui.view">
<field name="name">account.analytic.account.invoice.recurring.form.inherit</field>
<field name="name">Contract form</field>
<field name="model">account.analytic.account</field> <field name="model">account.analytic.account</field>
<field name="inherit_id" ref="analytic.view_account_analytic_account_form"/> <field name="inherit_id" ref="analytic.view_account_analytic_account_form"/>
<field name="mode">primary</field> <field name="mode">primary</field>
<field name="priority" eval="9999"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//div[@name='button_box']/.." position="before"> <xpath expr="//div[@name='button_box']/.." position="before">
<header> <header>
@ -79,9 +80,11 @@
<!-- Inherited Analytic Account list for contracts --> <!-- Inherited Analytic Account list for contracts -->
<record id="view_account_analytic_account_journal_tree" model="ir.ui.view"> <record id="view_account_analytic_account_journal_tree" model="ir.ui.view">
<field name="name">account.analytic.account.journal.list</field>
<field name="name">Contract list</field>
<field name="model">account.analytic.account</field> <field name="model">account.analytic.account</field>
<field name="inherit_id" ref="analytic.view_account_analytic_account_list" /> <field name="inherit_id" ref="analytic.view_account_analytic_account_list" />
<field name="mode">primary</field>
<field name="priority" eval="9999"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="partner_id" position="before"> <field name="partner_id" position="before">
<field name="journal_id" groups="account.group_account_user"/> <field name="journal_id" groups="account.group_account_user"/>
@ -94,7 +97,7 @@
<!-- Analytic Account search view for contract --> <!-- Analytic Account search view for contract -->
<record id="view_account_analytic_account_contract_search" model="ir.ui.view"> <record id="view_account_analytic_account_contract_search" model="ir.ui.view">
<field name="name">account.analytic.account.contract.search</field>
<field name="name">Contract search</field>
<field name="model">account.analytic.account</field> <field name="model">account.analytic.account</field>
<field name="inherit_id" ref="analytic.view_account_analytic_account_search"/> <field name="inherit_id" ref="analytic.view_account_analytic_account_search"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
@ -130,6 +133,20 @@
</field> </field>
</record> </record>
<record id="action_account_analytic_overdue_all_tree" model="ir.actions.act_window.view">
<field name="sequence" eval="1"/>
<field name="view_mode">tree</field>
<field name="view_id" ref="view_account_analytic_account_journal_tree"/>
<field name="act_window_id" ref="action_account_analytic_overdue_all"/>
</record>
<record id="action_account_analytic_overdue_all_form" model="ir.actions.act_window.view">
<field name="sequence" eval="2"/>
<field name="view_mode">form</field>
<field name="view_id" ref="account_analytic_account_recurring_form_form"/>
<field name="act_window_id" ref="action_account_analytic_overdue_all"/>
</record>
<menuitem id="menu_action_account_analytic_overdue_all" <menuitem id="menu_action_account_analytic_overdue_all"
parent="account.menu_finance_receivables" parent="account.menu_finance_receivables"
action="action_account_analytic_overdue_all" action="action_account_analytic_overdue_all"

Loading…
Cancel
Save