Browse Source

[MIG] contract: Migration to version 10.0

13.0-mig-contract
Pedro M. Baeza 8 years ago
committed by Administrator
parent
commit
f0097c2de7
  1. 10
      contract/README.rst
  2. 4
      contract/__manifest__.py
  3. 6
      contract/data/contract_cron.xml
  4. 17
      contract/models/contract.py
  5. 2
      contract/models/invoice.py
  6. 4
      contract/security/ir.model.access.csv
  7. 7
      contract/tests/test_contract.py
  8. 6
      contract/views/account_invoice_view.xml
  9. 12
      contract/views/contract.xml

10
contract/README.rst

@ -6,8 +6,9 @@
Contracts for recurrent invoicing 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 Configuration
============= =============
@ -19,9 +20,10 @@ Usage
To use this module, you need to: 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*. #. Check *Generate recurring invoices automatically*.
#. Fill fields for selecting the recurrency and invoice parameters: #. Fill fields for selecting the recurrency and invoice parameters:
* Journal * Journal
* Pricelist * Pricelist
* Period. It can be any interval of days, weeks, months, months last day or * 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 .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot :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 Known issues / Roadmap
====================== ======================

4
contract/__openerp__.py → contract/__manifest__.py

@ -5,13 +5,13 @@
{ {
'name': 'Contracts Management recurring', 'name': 'Contracts Management recurring',
'version': '9.0.1.1.0',
'version': '10.0.1.0.0',
'category': 'Contract Management', 'category': 'Contract Management',
'license': 'AGPL-3', 'license': 'AGPL-3',
'author': "OpenERP SA," 'author': "OpenERP SA,"
"Tecnativa," "Tecnativa,"
"Odoo Community Association (OCA)", "Odoo Community Association (OCA)",
'website': 'http://openerp.com',
'website': 'https://github.com/oca/contract',
'depends': ['base', 'account', 'analytic'], 'depends': ['base', 'account', 'analytic'],
'data': [ 'data': [
'security/ir.model.access.csv', 'security/ir.model.access.csv',

6
contract/data/contract_cron.xml

@ -1,6 +1,5 @@
<?xml version="1.0" encoding='UTF-8'?> <?xml version="1.0" encoding='UTF-8'?>
<openerp>
<data>
<odoo>
<record model="ir.cron" id="account_analytic_cron_for_invoice"> <record model="ir.cron" id="account_analytic_cron_for_invoice">
<field name="name">Generate Recurring Invoices from Contracts</field> <field name="name">Generate Recurring Invoices from Contracts</field>
@ -12,5 +11,4 @@
<field name="args" eval="'()'"/> <field name="args" eval="'()'"/>
</record> </record>
</data>
</openerp>
</odoo>

17
contract/models/contract.py

@ -8,10 +8,10 @@
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
import logging 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__) _logger = logging.getLogger(__name__)
@ -30,7 +30,7 @@ class AccountAnalyticInvoiceLine(models.Model):
price_unit = fields.Float('Unit Price', required=True) price_unit = fields.Float('Unit Price', required=True)
price_subtotal = fields.Float( price_subtotal = fields.Float(
compute='_compute_price_subtotal', compute='_compute_price_subtotal',
digits_compute=dp.get_precision('Account'),
digits=dp.get_precision('Account'),
string='Sub Total') string='Sub Total')
discount = fields.Float( discount = fields.Float(
string='Discount (%)', string='Discount (%)',
@ -155,7 +155,7 @@ class AccountAnalyticAccount(models.Model):
self.recurring_next_date = self.date_start self.recurring_next_date = self.date_start
@api.model @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': if recurring_rule_type == 'daily':
return relativedelta(days=interval) return relativedelta(days=interval)
elif recurring_rule_type == 'weekly': elif recurring_rule_type == 'weekly':
@ -175,7 +175,7 @@ class AccountAnalyticAccount(models.Model):
date_to = next_date - relativedelta(days=1) date_to = next_date - relativedelta(days=1)
else: else:
date_from = (date_start - date_from = (date_start -
self.get_relalive_delta(contract.recurring_rule_type,
self.get_relative_delta(contract.recurring_rule_type,
contract.recurring_interval) + contract.recurring_interval) +
relativedelta(days=1)) relativedelta(days=1))
date_to = date_start date_to = date_start
@ -267,7 +267,7 @@ class AccountAnalyticAccount(models.Model):
for contract in self: for contract in self:
old_date = fields.Date.from_string( old_date = fields.Date.from_string(
contract.recurring_next_date or fields.Date.today()) 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) contract.recurring_rule_type, contract.recurring_interval)
ctx = self.env.context.copy() ctx = self.env.context.copy()
ctx.update({ ctx.update({
@ -287,6 +287,5 @@ class AccountAnalyticAccount(models.Model):
def cron_recurring_create_invoice(self): def cron_recurring_create_invoice(self):
contracts = self.search( contracts = self.search(
[('recurring_next_date', '<=', fields.date.today()), [('recurring_next_date', '<=', fields.date.today()),
('account_type', '=', 'normal'),
('recurring_invoices', '=', True)]) ('recurring_invoices', '=', True)])
return contracts.recurring_create_invoice() return contracts.recurring_create_invoice()

2
contract/models/invoice.py

@ -2,7 +2,7 @@
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com> # © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# 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 openerp import fields, models
from odoo import fields, models
class AccountInvoice(models.Model): class AccountInvoice(models.Model):

4
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" "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

7
contract/tests/test_contract.py

@ -2,8 +2,8 @@
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com> # © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# 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 openerp.exceptions import ValidationError
from openerp.tests.common import TransactionCase
from odoo.exceptions import ValidationError
from odoo.tests.common import TransactionCase
class TestContract(TransactionCase): class TestContract(TransactionCase):
@ -12,6 +12,8 @@ class TestContract(TransactionCase):
super(TestContract, self).setUp() super(TestContract, self).setUp()
self.partner = self.env.ref('base.res_partner_2') self.partner = self.env.ref('base.res_partner_2')
self.product = self.env.ref('product.product_product_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.product.description_sale = 'Test description sale'
self.contract = self.env['account.analytic.account'].create({ self.contract = self.env['account.analytic.account'].create({
'name': 'Test Contract', 'name': 'Test Contract',
@ -53,6 +55,7 @@ class TestContract(TransactionCase):
self.assertEqual(self.contract.recurring_next_date, '2016-03-29') self.assertEqual(self.contract.recurring_next_date, '2016-03-29')
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.assertAlmostEqual(self.inv_line.price_subtotal, 50.0) self.assertAlmostEqual(self.inv_line.price_subtotal, 50.0)
self.assertEqual(self.contract.partner_id.user_id, self.assertEqual(self.contract.partner_id.user_id,
self.invoice_monthly.user_id) self.invoice_monthly.user_id)

6
contract/views/account_invoice_view.xml

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<odoo>
<!-- Invoice search view with contract --> <!-- Invoice search view with contract -->
<record id="view_account_invoice_filter_contract" model="ir.ui.view"> <record id="view_account_invoice_filter_contract" model="ir.ui.view">
@ -15,5 +14,4 @@
</field> </field>
</record> </record>
</data>
</openerp>
</odoo>

12
contract/views/contract.xml

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<odoo>
<record id="act_recurring_invoices" model="ir.actions.act_window"> <record id="act_recurring_invoices" model="ir.actions.act_window">
<field name="context">{'search_default_contract_id': <field name="context">{'search_default_contract_id':
@ -19,7 +18,7 @@
<field name="inherit_id" ref="analytic.view_account_analytic_account_form"/> <field name="inherit_id" ref="analytic.view_account_analytic_account_form"/>
<field eval="40" name="priority"/> <field eval="40" name="priority"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<notebook position="before">
<group name="main" position="after">
<separator string="Recurring Invoices" attrs="{'invisible': [('recurring_invoices','!=',True)]}"/> <separator string="Recurring Invoices" attrs="{'invisible': [('recurring_invoices','!=',True)]}"/>
<div> <div>
<field name="recurring_invoices" class="oe_inline"/> <field name="recurring_invoices" class="oe_inline"/>
@ -63,7 +62,7 @@
<p colspan="2"> <strong>#START#</strong>: Start date of the invoiced period</p> <p colspan="2"> <strong>#START#</strong>: Start date of the invoiced period</p>
<p colspan="2"> <strong>#END#</strong>: End date of the invoiced period</p> <p colspan="2"> <strong>#END#</strong>: End date of the invoiced period</p>
</group> </group>
</notebook>
</group>
</field> </field>
</record> </record>
@ -110,7 +109,6 @@
</p> </p>
</field> </field>
</record> </record>
<menuitem action="action_account_analytic_overdue_all" id="menu_action_account_analytic_overdue_all" sequence="8" parent="base.menu_sales"/>
<menuitem action="action_account_analytic_overdue_all" id="menu_action_account_analytic_overdue_all" sequence="99" parent="account.menu_finance_receivables"/>
</data>
</openerp>
</odoo>
Loading…
Cancel
Save