Browse Source

[MIG] contract_payment_mode: Migration to 10.0

pull/164/head
David Vidal 8 years ago
committed by cubells
parent
commit
557f0053de
  1. 5
      contract_payment_mode/README.rst
  2. 1
      contract_payment_mode/__init__.py
  3. 3
      contract_payment_mode/__manifest__.py
  4. 2
      contract_payment_mode/hooks.py
  5. 14
      contract_payment_mode/models/contract.py
  6. 47
      contract_payment_mode/tests/test_contract_payment.py

5
contract_payment_mode/README.rst

@ -17,7 +17,7 @@ Your user should be a Sales Manager or Accountant.
Usage Usage
===== =====
#. Go to *Sales > Sales > Contracts*.
#. Go to *Accounting > Sales > Contracts*.
#. Create one. #. Create one.
#. Select a partner to which invoice. #. Select a partner to which invoice.
#. If the partner has a payment mode, this payment mode is selected here. #. If the partner has a payment mode, this payment mode is selected here.
@ -30,7 +30,7 @@ Usage
.. 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
Bug Tracker Bug Tracker
=========== ===========
@ -49,6 +49,7 @@ Contributors
* Ángel Moya <angel.moya@domatix.com> * Ángel Moya <angel.moya@domatix.com>
* Antonio Espinosa <antonioea@antiun.com> * Antonio Espinosa <antonioea@antiun.com>
* Vicent Cubells <vicent.cubells@tecnativa.com> * Vicent Cubells <vicent.cubells@tecnativa.com>
* David Vidal <david.vidal@tecnativa.com>
Maintainer Maintainer

1
contract_payment_mode/__init__.py

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2016 Antiun Ingenieria S.L. - Antonio Espinosa
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models from . import models

3
contract_payment_mode/__openerp__.py → contract_payment_mode/__manifest__.py

@ -2,12 +2,13 @@
# Copyright 2015 Domatix (<www.domatix.com>) # Copyright 2015 Domatix (<www.domatix.com>)
# Copyright 2016 Antiun Ingenieria S.L. - Antonio Espinosa # Copyright 2016 Antiun Ingenieria S.L. - Antonio Espinosa
# Copyright 2017 Tecnativa - Vicent Cubells # Copyright 2017 Tecnativa - Vicent Cubells
# Copyright 2017 Tecnativa - David Vidal
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{ {
'name': 'Contract Payment Mode', 'name': 'Contract Payment Mode',
'summary': 'Payment mode in contracts and their invoices', 'summary': 'Payment mode in contracts and their invoices',
'version': '9.0.1.0.0',
'version': '10.0.1.0.0',
'author': 'Domatix, ' 'author': 'Domatix, '
'Tecnativa, ' 'Tecnativa, '
'Odoo Community Association (OCA)', 'Odoo Community Association (OCA)',

2
contract_payment_mode/hooks.py

@ -2,7 +2,7 @@
# Copyright 2016 Antiun Ingenieria S.L. - Antonio Espinosa # Copyright 2016 Antiun Ingenieria S.L. - Antonio Espinosa
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import api, SUPERUSER_ID
from odoo import api, SUPERUSER_ID
import logging import logging
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)

14
contract_payment_mode/models/contract.py

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from openerp import api, fields, models
from odoo import api, fields, models
class AccountAnalyticAccount(models.Model): class AccountAnalyticAccount(models.Model):
@ -16,12 +16,10 @@ class AccountAnalyticAccount(models.Model):
if self.partner_id.customer_payment_mode_id: if self.partner_id.customer_payment_mode_id:
self.payment_mode_id = self.partner_id.customer_payment_mode_id.id self.payment_mode_id = self.partner_id.customer_payment_mode_id.id
@api.model
def _prepare_invoice_data(self, contract):
@api.multi
def _prepare_invoice(self):
invoice_vals = super(AccountAnalyticAccount, self)._prepare_invoice() invoice_vals = super(AccountAnalyticAccount, self)._prepare_invoice()
if contract.payment_mode_id:
invoice_vals['payment_mode_id'] = contract.payment_mode_id.id
invoice_vals['partner_bank_id'] = (
contract.partner_id.bank_ids[:1].id
)
if self.payment_mode_id:
invoice_vals['payment_mode_id'] = self.payment_mode_id.id
invoice_vals['partner_bank_id'] = self.partner_id.bank_ids[:1].id
return invoice_vals return invoice_vals

47
contract_payment_mode/tests/test_contract_payment.py

@ -1,9 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2015 Antiun Ingenieria S.L. - Antonio Espinosa # Copyright 2015 Antiun Ingenieria S.L. - Antonio Espinosa
# Copyright 2017 Tecnativa - Vicent Cubells # Copyright 2017 Tecnativa - Vicent Cubells
# Copyright 2017 Tecnativa - David Vidal
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp.tests import common
from odoo.tests import common
from ..hooks import post_init_hook from ..hooks import post_init_hook
@ -12,10 +13,17 @@ class TestContractPaymentInit(common.SavepointCase):
def setUpClass(cls): def setUpClass(cls):
super(TestContractPaymentInit, cls).setUpClass() super(TestContractPaymentInit, cls).setUpClass()
cls.payment_method = cls.env.ref(
'account.account_payment_method_manual_in')
cls.payment_mode = cls.env.ref(
'account_payment_mode.payment_mode_inbound_ct1')
cls.payment_method = cls.env['account.payment.method'].create({
'name': 'Test Payment Method',
'code': 'Test',
'payment_type': 'inbound',
})
cls.payment_mode = cls.env['account.payment.mode'].create({
'name': 'Test payment mode',
'active': True,
'payment_method_id': cls.payment_method.id,
'bank_account_link': 'variable',
})
cls.partner = cls.env['res.partner'].create({ cls.partner = cls.env['res.partner'].create({
'name': 'Test contract partner', 'name': 'Test contract partner',
'customer_payment_mode_id': cls.payment_mode, 'customer_payment_mode_id': cls.payment_mode,
@ -30,12 +38,12 @@ class TestContractPaymentInit(common.SavepointCase):
cls.contract = cls.env['account.analytic.account'].create({ cls.contract = cls.env['account.analytic.account'].create({
'name': 'Maintenance of Servers', 'name': 'Maintenance of Servers',
}) })
def _contract_payment_mode_id(self, contract_id):
contract = self.env['account.analytic.account'].search([
('id', '=', contract_id),
])
return contract.payment_mode_id.id
company = cls.env.ref('base.main_company')
cls.journal = cls.env['account.journal'].create({
'name': 'Sale Journal - Test',
'code': 'HRTSJ',
'type': 'sale',
'company_id': company.id})
def test_post_init_hook(self): def test_post_init_hook(self):
contract = self.env['account.analytic.account'].create({ contract = self.env['account.analytic.account'].create({
@ -43,15 +51,15 @@ class TestContractPaymentInit(common.SavepointCase):
'partner_id': self.partner.id, 'partner_id': self.partner.id,
'payment_mode_id': self.payment_mode.id, 'payment_mode_id': self.payment_mode.id,
}) })
self.assertEqual(self._contract_payment_mode_id(contract.id),
self.payment_mode.id)
self.assertEqual(contract.payment_mode_id,
self.payment_mode)
contract.payment_mode_id = False contract.payment_mode_id = False
self.assertEqual(self._contract_payment_mode_id(contract.id), False)
self.assertEqual(contract.payment_mode_id.id, False)
post_init_hook(self.cr, self.env) post_init_hook(self.cr, self.env)
self.assertEqual(self._contract_payment_mode_id(contract.id),
self.payment_mode.id)
self.assertEqual(contract.payment_mode_id,
self.payment_mode)
def test_contract_and_invoices(self): def test_contract_and_invoices(self):
self.contract.write({'partner_id': self.partner.id}) self.contract.write({'partner_id': self.partner.id})
@ -69,14 +77,13 @@ class TestContractPaymentInit(common.SavepointCase):
'uom_id': self.product.uom_id.id, 'uom_id': self.product.uom_id.id,
})] })]
}) })
res = self.contract._prepare_invoice_data(self.contract)
self.assertEqual(res.get('partner_id'), self.contract.partner_id.id)
self.assertEqual(res.get('payment_mode_id'),
self.contract.payment_mode_id.id)
self.contract.recurring_create_invoice() self.contract.recurring_create_invoice()
new_invoice = self.env['account.invoice'].search([ new_invoice = self.env['account.invoice'].search([
('contract_id', '=', self.contract.id) ('contract_id', '=', self.contract.id)
]) ])
self.assertEqual(new_invoice.partner_id, self.contract.partner_id)
self.assertEqual(new_invoice.payment_mode_id,
self.contract.payment_mode_id)
self.assertEqual(len(new_invoice.ids), 1) self.assertEqual(len(new_invoice.ids), 1)
self.contract.recurring_create_invoice() self.contract.recurring_create_invoice()
self.assertEqual(self.contract.payment_mode_id, self.assertEqual(self.contract.payment_mode_id,

Loading…
Cancel
Save