mirror of
https://github.com/NaN-tic/trytond-contract_payment_type.git
synced 2023-12-14 06:13:04 +01:00
Backport the code to Python 2
This commit is contained in:
parent
00af56e4bd
commit
1937a8d4b1
|
@ -1,11 +1,12 @@
|
||||||
# The COPYRIGHT file at the top level of this repository contains the full
|
# The COPYRIGHT file at the top level of this repository contains the full
|
||||||
# copyright notices and license terms.
|
# copyright notices and license terms.
|
||||||
|
from __future__ import absolute_import
|
||||||
from trytond.pool import Pool
|
from trytond.pool import Pool
|
||||||
import contract
|
from . import contract
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
Pool.register(
|
Pool.register(
|
||||||
contract.PaymentType,
|
contract.PaymentType,
|
||||||
contract.Contract,
|
contract.Contract,
|
||||||
contract.ContractConsumption,
|
contract.ContractConsumption,
|
||||||
module='contract_payment_type', type_='model')
|
module=u'contract_payment_type', type_=u'model')
|
||||||
|
|
31
contract.py
31
contract.py
|
@ -1,39 +1,40 @@
|
||||||
# The COPYRIGHT file at the top level of this repository contains
|
# The COPYRIGHT file at the top level of this repository contains
|
||||||
# the full copyright notices and license terms.
|
# the full copyright notices and license terms.
|
||||||
|
from __future__ import absolute_import
|
||||||
from trytond.model import fields
|
from trytond.model import fields
|
||||||
from trytond.pool import Pool, PoolMeta
|
from trytond.pool import Pool, PoolMeta
|
||||||
from trytond.modules.account_bank.account import BankMixin
|
from trytond.modules.account_bank.account import BankMixin
|
||||||
|
|
||||||
__all__ = ['PaymentType', 'Contract', 'ContractConsumption']
|
__all__ = [u'PaymentType', u'Contract', u'ContractConsumption']
|
||||||
|
|
||||||
|
|
||||||
class PaymentType:
|
class PaymentType(object):
|
||||||
__metaclass__ = PoolMeta
|
__metaclass__ = PoolMeta
|
||||||
__name__ = 'account.payment.type'
|
__name__ = u'account.payment.type'
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __setup__(cls):
|
def __setup__(cls):
|
||||||
super(PaymentType, cls).__setup__()
|
super(PaymentType, cls).__setup__()
|
||||||
cls._check_modify_related_models.add(('contract', 'payment_type'))
|
cls._check_modify_related_models.add((u'contract', u'payment_type'))
|
||||||
|
|
||||||
|
|
||||||
class Contract(BankMixin):
|
class Contract(BankMixin):
|
||||||
__name__ = 'contract'
|
|
||||||
__metaclass__ = PoolMeta
|
__metaclass__ = PoolMeta
|
||||||
|
__name__ = u'contract'
|
||||||
|
|
||||||
payment_type = fields.Many2One('account.payment.type', 'Payment Type',
|
payment_type = fields.Many2One(u'account.payment.type', u'Payment Type',
|
||||||
domain=[
|
domain=[
|
||||||
('kind', 'in', ['both', 'receivable']),
|
(u'kind', u'in', [u'both', u'receivable']),
|
||||||
])
|
])
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def default_payment_type(cls):
|
def default_payment_type(cls):
|
||||||
PaymentType = Pool().get('account.payment.type')
|
PaymentType = Pool().get(u'account.payment.type')
|
||||||
payment_types = PaymentType.search(cls.payment_type.domain)
|
payment_types = PaymentType.search(cls.payment_type.domain)
|
||||||
if len(payment_types) == 1:
|
if len(payment_types) == 1:
|
||||||
return payment_types[0].id
|
return payment_types[0].id
|
||||||
|
|
||||||
@fields.depends('party')
|
@fields.depends(u'party')
|
||||||
def on_change_party(self):
|
def on_change_party(self):
|
||||||
self.payment_type = None
|
self.payment_type = None
|
||||||
self.bank_account = None
|
self.bank_account = None
|
||||||
|
@ -43,22 +44,22 @@ class Contract(BankMixin):
|
||||||
if self.payment_type:
|
if self.payment_type:
|
||||||
self._get_bank_account()
|
self._get_bank_account()
|
||||||
|
|
||||||
class ContractConsumption:
|
class ContractConsumption(object):
|
||||||
__name__ = 'contract.consumption'
|
|
||||||
__metaclass__ = PoolMeta
|
__metaclass__ = PoolMeta
|
||||||
|
__name__ = u'contract.consumption'
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _group_invoice_key(cls, line):
|
def _group_invoice_key(cls, line):
|
||||||
consumption, invoice_line = line
|
consumption, invoice_line = line
|
||||||
return super(ContractConsumption, cls)._group_invoice_key(line) + [
|
return super(ContractConsumption, cls)._group_invoice_key(line) + [
|
||||||
('payment_type', consumption.contract.payment_type),
|
(u'payment_type', consumption.contract.payment_type),
|
||||||
('bank_account', consumption.contract.bank_account),
|
(u'bank_account', consumption.contract.bank_account),
|
||||||
]
|
]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _get_invoice(cls, keys):
|
def _get_invoice(cls, keys):
|
||||||
invoice = super(ContractConsumption, cls)._get_invoice(keys)
|
invoice = super(ContractConsumption, cls)._get_invoice(keys)
|
||||||
values = dict(keys)
|
values = dict(keys)
|
||||||
invoice.payment_type = values['payment_type']
|
invoice.payment_type = values[u'payment_type']
|
||||||
invoice.bank_account = values['bank_account']
|
invoice.bank_account = values[u'bank_account']
|
||||||
return invoice
|
return invoice
|
||||||
|
|
104
setup.py
104
setup.py
|
@ -1,13 +1,15 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
|
from __future__ import absolute_import
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
|
from io import open
|
||||||
|
|
||||||
MODULE = 'contract_payment_type'
|
MODULE = u'contract_payment_type'
|
||||||
PREFIX = 'nantic'
|
PREFIX = u'nantic'
|
||||||
MODULE2PREFIX = {}
|
MODULE2PREFIX = {}
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,83 +19,83 @@ def read(fname):
|
||||||
|
|
||||||
def get_require_version(name):
|
def get_require_version(name):
|
||||||
if minor_version % 2:
|
if minor_version % 2:
|
||||||
require = '%s >= %s.%s.dev0, < %s.%s'
|
require = u'%s >= %s.%s.dev0, < %s.%s'
|
||||||
else:
|
else:
|
||||||
require = '%s >= %s.%s, < %s.%s'
|
require = u'%s >= %s.%s, < %s.%s'
|
||||||
require %= (name, major_version, minor_version,
|
require %= (name, major_version, minor_version,
|
||||||
major_version, minor_version + 1)
|
major_version, minor_version + 1)
|
||||||
return require
|
return require
|
||||||
|
|
||||||
config = ConfigParser.ConfigParser()
|
config = ConfigParser.ConfigParser()
|
||||||
config.readfp(open('tryton.cfg'))
|
config.readfp(open(u'tryton.cfg'))
|
||||||
info = dict(config.items('tryton'))
|
info = dict(config.items(u'tryton'))
|
||||||
for key in ('depends', 'extras_depend', 'xml'):
|
for key in (u'depends', u'extras_depend', u'xml'):
|
||||||
if key in info:
|
if key in info:
|
||||||
info[key] = info[key].strip().splitlines()
|
info[key] = info[key].strip().splitlines()
|
||||||
|
|
||||||
version = info.get('version', '0.0.1')
|
version = info.get(u'version', u'0.0.1')
|
||||||
major_version, minor_version, _ = version.split('.', 2)
|
major_version, minor_version, _ = version.split(u'.', 2)
|
||||||
major_version = int(major_version)
|
major_version = int(major_version)
|
||||||
minor_version = int(minor_version)
|
minor_version = int(minor_version)
|
||||||
|
|
||||||
requires = []
|
requires = []
|
||||||
for dep in info.get('depends', []):
|
for dep in info.get(u'depends', []):
|
||||||
if not re.match(r'(ir|res|webdav)(\W|$)', dep):
|
if not re.match(ur'(ir|res|webdav)(\W|$)', dep):
|
||||||
prefix = MODULE2PREFIX.get(dep, 'trytond')
|
prefix = MODULE2PREFIX.get(dep, u'trytond')
|
||||||
requires.append('%s_%s >= %s.%s, < %s.%s' %
|
requires.append(u'%s_%s >= %s.%s, < %s.%s' %
|
||||||
(prefix, dep, major_version, minor_version,
|
(prefix, dep, major_version, minor_version,
|
||||||
major_version, minor_version + 1))
|
major_version, minor_version + 1))
|
||||||
requires.append(get_require_version('trytond'))
|
requires.append(get_require_version(u'trytond'))
|
||||||
|
|
||||||
tests_require = [get_require_version('proteus')]
|
tests_require = [get_require_version(u'proteus')]
|
||||||
|
|
||||||
setup(name='%s_%s' % (PREFIX, MODULE),
|
setup(name=u'%s_%s' % (PREFIX, MODULE),
|
||||||
version=version,
|
version=version,
|
||||||
description='',
|
description=u'',
|
||||||
long_description=read('README'),
|
long_description=read(u'README'),
|
||||||
author='NaN·tic',
|
author=u'NaN·tic',
|
||||||
author_email='info@nan-tic.com',
|
author_email=u'info@nan-tic.com',
|
||||||
url='http://www.nan-tic.com/',
|
url=u'http://www.nan-tic.com/',
|
||||||
download_url="https://bitbucket.org/nantic/trytond-%s" % MODULE,
|
download_url=u"https://bitbucket.org/nantic/trytond-%s" % MODULE,
|
||||||
package_dir={'trytond.modules.%s' % MODULE: '.'},
|
package_dir={u'trytond.modules.%s' % MODULE: u'.'},
|
||||||
packages=[
|
packages=[
|
||||||
'trytond.modules.%s' % MODULE,
|
u'trytond.modules.%s' % MODULE,
|
||||||
'trytond.modules.%s.tests' % MODULE,
|
u'trytond.modules.%s.tests' % MODULE,
|
||||||
],
|
],
|
||||||
package_data={
|
package_data={
|
||||||
'trytond.modules.%s' % MODULE: (info.get('xml', [])
|
u'trytond.modules.%s' % MODULE: (info.get(u'xml', [])
|
||||||
+ ['tryton.cfg', 'locale/*.po', 'tests/*.rst']),
|
+ [u'tryton.cfg', u'locale/*.po', u'tests/*.rst']),
|
||||||
},
|
},
|
||||||
classifiers=[
|
classifiers=[
|
||||||
'Development Status :: 5 - Production/Stable',
|
u'Development Status :: 5 - Production/Stable',
|
||||||
'Environment :: Plugins',
|
u'Environment :: Plugins',
|
||||||
'Framework :: Tryton',
|
u'Framework :: Tryton',
|
||||||
'Intended Audience :: Developers',
|
u'Intended Audience :: Developers',
|
||||||
'Intended Audience :: Financial and Insurance Industry',
|
u'Intended Audience :: Financial and Insurance Industry',
|
||||||
'Intended Audience :: Legal Industry',
|
u'Intended Audience :: Legal Industry',
|
||||||
'License :: OSI Approved :: GNU General Public License (GPL)',
|
u'License :: OSI Approved :: GNU General Public License (GPL)',
|
||||||
'Natural Language :: Bulgarian',
|
u'Natural Language :: Bulgarian',
|
||||||
'Natural Language :: Catalan',
|
u'Natural Language :: Catalan',
|
||||||
'Natural Language :: Czech',
|
u'Natural Language :: Czech',
|
||||||
'Natural Language :: Dutch',
|
u'Natural Language :: Dutch',
|
||||||
'Natural Language :: English',
|
u'Natural Language :: English',
|
||||||
'Natural Language :: French',
|
u'Natural Language :: French',
|
||||||
'Natural Language :: German',
|
u'Natural Language :: German',
|
||||||
'Natural Language :: Russian',
|
u'Natural Language :: Russian',
|
||||||
'Natural Language :: Spanish',
|
u'Natural Language :: Spanish',
|
||||||
'Operating System :: OS Independent',
|
u'Operating System :: OS Independent',
|
||||||
'Programming Language :: Python :: 2.6',
|
u'Programming Language :: Python :: 2.6',
|
||||||
'Programming Language :: Python :: 2.7',
|
u'Programming Language :: Python :: 2.7',
|
||||||
'Topic :: Office/Business',
|
u'Topic :: Office/Business',
|
||||||
],
|
],
|
||||||
license='GPL-3',
|
license=u'GPL-3',
|
||||||
install_requires=requires,
|
install_requires=requires,
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
entry_points="""
|
entry_points=u"""
|
||||||
[trytond.modules]
|
[trytond.modules]
|
||||||
%s = trytond.modules.%s
|
%s = trytond.modules.%s
|
||||||
""" % (MODULE, MODULE),
|
""" % (MODULE, MODULE),
|
||||||
test_suite='tests',
|
test_suite=u'tests',
|
||||||
test_loader='trytond.test_loader:Loader',
|
test_loader=u'trytond.test_loader:Loader',
|
||||||
tests_require=tests_require,
|
tests_require=tests_require,
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
# The COPYRIGHT file at the top level of this repository contains the full
|
# The COPYRIGHT file at the top level of this repository contains the full
|
||||||
# copyright notices and license terms.
|
# copyright notices and license terms.
|
||||||
|
from __future__ import absolute_import
|
||||||
try:
|
try:
|
||||||
from trytond.modules.contract.tests.test_contract_payment_type import suite
|
from trytond.modules.contract.tests.test_contract_payment_type import suite
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from .test_contract_payment_type import suite
|
from .test_contract_payment_type import suite
|
||||||
|
|
||||||
__all__ = ['suite']
|
__all__ = [u'suite']
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# The COPYRIGHT file at the top level of this repository contains the full
|
# The COPYRIGHT file at the top level of this repository contains the full
|
||||||
# copyright notices and license terms.
|
# copyright notices and license terms.
|
||||||
|
from __future__ import absolute_import
|
||||||
import doctest
|
import doctest
|
||||||
import unittest
|
import unittest
|
||||||
import trytond.tests.test_tryton
|
import trytond.tests.test_tryton
|
||||||
|
@ -8,16 +9,16 @@ from trytond.tests.test_tryton import doctest_teardown, doctest_checker
|
||||||
|
|
||||||
|
|
||||||
class TestContractPaymentTypeCase(ModuleTestCase):
|
class TestContractPaymentTypeCase(ModuleTestCase):
|
||||||
'Test Contract Payment Type module'
|
u'Test Contract Payment Type module'
|
||||||
module = 'contract_payment_type'
|
module = u'contract_payment_type'
|
||||||
|
|
||||||
|
|
||||||
def suite():
|
def suite():
|
||||||
suite = trytond.tests.test_tryton.suite()
|
suite = trytond.tests.test_tryton.suite()
|
||||||
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
|
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
|
||||||
TestContractPaymentTypeCase))
|
TestContractPaymentTypeCase))
|
||||||
suite.addTests(doctest.DocFileSuite('scenario_contract_payment_type.rst',
|
suite.addTests(doctest.DocFileSuite(u'scenario_contract_payment_type.rst',
|
||||||
tearDown=doctest_teardown, encoding='utf-8',
|
tearDown=doctest_teardown, encoding=u'utf-8',
|
||||||
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE,
|
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE,
|
||||||
checker=doctest_checker))
|
checker=doctest_checker))
|
||||||
return suite
|
return suite
|
||||||
|
|
Loading…
Reference in a new issue