~therp-nl/banking-addons/ba70-refactor_import_transactions

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
##############################################################################
#
#    Copyright (C) 2009 EduSense BV (<http://www.edusense.nl>).
#    Copyright (C) 2011 credativ Ltd (<http://www.credativ.co.uk>).
#    All Rights Reserved
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from osv import osv, fields
from datetime import date
from tools.translate import _

class hsbc_export(osv.osv):
    '''HSBC Export'''
    _name = 'banking.export.hsbc'
    _description = __doc__
    _rec_name = 'execution_date'

    _columns = {
        'payment_order_ids': fields.many2many(
            'payment.order',
            'account_payment_order_hsbc_rel',
            'banking_export_hsbc_id', 'account_order_id',
            'Payment Orders',
            readonly=True),
        'identification':
            fields.char('Identification', size=15, readonly=True, select=True),
        'execution_date':
            fields.date('Execution Date',readonly=True),
        'no_transactions':
            fields.integer('Number of Transactions', readonly=True),
        'total_amount':
            fields.float('Total Amount', readonly=True),
        'date_generated':
            fields.datetime('Generation Date', readonly=True, select=True),
        'file':
            fields.binary('HSBC File', readonly=True),
        'state':
            fields.selection([
                ('draft', 'Draft'),
                ('sent', 'Sent'),
                ('done', 'Reconciled'),
            ], 'State', readonly=True),
    }

    _defaults = {
        'date_generated': lambda *a: date.today().strftime('%Y-%m-%d'),
        'state': lambda *a: 'draft',
    }
hsbc_export()


class payment_line(osv.osv):
    '''
    The standard payment order is using a mixture of details from the partner record
    and the res.partner.bank record. For, instance, the account holder name is coming
    from the res.partner.bank record, but the company name and address are coming from
    the partner address record. This is problematic because the HSBC payment format
    is validating for alphanumeric characters in the company name and address. So,
    "Great Company Ltd." and "Great Company s.a." will cause an error because they have
    full-stops in the name.

    A better approach is to use the name and address details from the res.partner.bank
    record always. This way, the address details can be sanitized for the payments, 
    whilst being able to print the proper name and address throughout the rest of the
    system e.g. on invoices.
    '''
    _name = 'payment.line'
    _inherit = 'payment.line'

    def info_owner(self, cr, uid, ids, name=None, args=None, context=None):
        if not ids: return {}

        result = {}
        info=''
        for line in self.browse(cr, uid, ids, context=context):
            owner = line.order_id.mode.bank_id

            name = owner.owner_name or owner.partner_id.name
            st = owner.street and owner.street or ''
            st1 = '' #no street2 in res.partner.bank
            zip = owner.zip and owner.zip or ''
            city = owner.city and owner.city or  ''
            zip_city = zip + ' ' + city
            cntry = owner.country_id and owner.country_id.name or ''
            info = name + "\n" + st + " " + st1 + "\n" + zip_city + "\n" +cntry
            result[line.id] = info
        return result

    def info_partner(self, cr, uid, ids, name=None, args=None, context=None):
        if not ids: return {}
        result = {}
        info = ''

        for line in self.browse(cr, uid, ids, context=context):
            partner = line.bank_id

            name = partner.owner_name or partner.partner_id.name
            st = partner.street and partner.street or ''
            st1 = '' #no street2 in res.partner.bank
            zip = partner.zip and partner.zip or ''
            city = partner.city and partner.city or  ''
            zip_city = zip + ' ' + city
            cntry = partner.country_id and partner.country_id.name or ''
            info = name + "\n" + st + " " + st1 + "\n" + zip_city + "\n" +cntry
            result[line.id] = info

        return result


    # Define the info_partner and info_owner so we can override the methods
    _columns = {
        'info_owner': fields.function(info_owner, string="Owner Account", type="text", help='Address of the Main Partner'),
        'info_partner': fields.function(info_partner, string="Destination Account", type="text", help='Address of the Ordering Customer.'),
    }

payment_line()


# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: