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