Use attachments instead of creating a specific object for each kind of payment order

This commit is contained in:
Alexis de Lattre
2015-01-29 16:30:02 +01:00
committed by Dũng (Trần Đình)
parent 24a7584c2c
commit c20fd55014
9 changed files with 86 additions and 201 deletions

View File

@@ -21,4 +21,3 @@
##############################################################################
from . import wizard
from . import models

View File

@@ -1,8 +1,8 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# SEPA Credit Transfer module for OpenERP
# Copyright (C) 2010-2013 Akretion (http://www.akretion.com)
# SEPA Credit Transfer module for Odoo
# Copyright (C) 2010-2015 Akretion (http://www.akretion.com)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
#
# This program is free software: you can redistribute it and/or modify
@@ -30,14 +30,9 @@
'website': 'https://github.com/OCA/bank-payment',
'category': 'Banking addons',
'depends': ['account_banking_pain_base'],
'external_dependencies': {
'python': ['unidecode', 'lxml'],
},
'data': [
'views/account_banking_sepa_view.xml',
'wizard/export_sepa_view.xml',
'data/payment_type_sepa_sct.xml',
'security/ir.model.access.csv',
],
'demo': [
'demo/sepa_credit_transfer_demo.xml'

View File

@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2015 Akretion (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
#
# 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 openerp import pooler, SUPERUSER_ID
def migrate(cr, version):
if not version:
return
pool = pooler.get_pool(cr.dbname)
cr.execute('''
SELECT
old_sepa.file,
rel.account_order_id AS payment_order_id,
payment_order.reference
FROM migration_banking_export_sepa old_sepa
LEFT JOIN migration_account_payment_order_sepa_rel rel
ON old_sepa.id=rel.banking_export_sepa_id
LEFT JOIN payment_order ON payment_order.id=rel.account_order_id
''')
for sepa_file in cr.dictfetchall():
filename = 'sct_%s.xml' % sepa_file['reference'].replace('/', '-')
pool['ir.attachment'].create(
cr, SUPERUSER_ID, {
'name': filename,
'res_id': sepa_file['payment_order_id'],
'res_model': 'payment.order',
'datas': str(sepa_file['file']),
})
return

View File

@@ -1,8 +1,7 @@
# -*- encoding: utf-8 -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# SEPA Credit Transfer module for OpenERP
# Copyright (C) 2010-2013 Akretion (http://www.akretion.com)
# Copyright (C) 2015 Akretion (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
#
# This program is free software: you can redistribute it and/or modify
@@ -20,4 +19,14 @@
#
##############################################################################
from . import account_banking_sepa
def migrate(cr, version):
if not version:
return
cr.execute(
'ALTER TABLE banking_export_sepa '
'RENAME TO migration_banking_export_sepa')
cr.execute(
'ALTER TABLE account_payment_order_sepa_rel '
'RENAME TO migration_account_payment_order_sepa_rel')

View File

@@ -1,80 +0,0 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# SEPA Credit Transfer module for OpenERP
# Copyright (C) 2010-2013 Akretion (http://www.akretion.com)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
#
# 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 openerp import models, fields, api
from openerp.addons.decimal_precision import decimal_precision as dp
try:
from unidecode import unidecode
except ImportError:
unidecode = None
class BankingExportSepa(models.Model):
"""SEPA export"""
_name = 'banking.export.sepa'
_description = __doc__
_rec_name = 'filename'
@api.one
def _generate_filename(self):
ref = self.payment_order_ids.reference
if ref:
label = unidecode(ref.replace('/', '-'))
else:
label = 'error'
self.filename = 'sct_%s.xml' % label
payment_order_ids = fields.Many2many(
comodel_name='payment.order', column1='banking_export_sepa_id',
column2='account_order_id', relation='account_payment_order_sepa_rel',
string='Payment Orders', readonly=True)
nb_transactions = fields.Integer(string='Number of Transactions',
readonly=True)
total_amount = fields.Float(string='Total Amount',
digits_compute=dp.get_precision('Account'),
readonly=True)
batch_booking = fields.Boolean(
'Batch Booking', readonly=True,
help="If true, the bank statement will display only one debit line "
"for all the wire transfers of the SEPA XML file ; if false, "
"the bank statement will display one debit line per wire "
"transfer of the SEPA XML file.")
charge_bearer = fields.Selection(
[('SLEV', 'Following Service Level'),
('SHAR', 'Shared'),
('CRED', 'Borne by Creditor'),
('DEBT', 'Borne by Debtor')], string='Charge Bearer', readonly=True,
help="Following service level : transaction charges are to be applied "
"following the rules agreed in the service level and/or scheme "
"(SEPA Core messages must use this). Shared : transaction "
"charges on the creditor side are to be borne by the creditor, "
"transaction charges on the debtor side are to be borne by the "
"debtor. Borne by creditor : all transaction charges are to be "
"borne by the creditor. Borne by debtor : all transaction "
"charges are to be borne by the debtor.")
create_date = fields.Datetime('Generation Date', readonly=True)
file = fields.Binary('SEPA XML File', readonly=True)
filename = fields.Char(string='Filename', size=256, readonly=True,
compute=_generate_filename)
state = fields.Selection([('draft', 'Draft'), ('sent', 'Sent')],
string='State', readonly=True, default='draft')

View File

@@ -1,2 +0,0 @@
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
"access_banking_export_sepa","Full access on banking.export.sepa","model_banking_export_sepa","account_payment.group_account_payment",1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_banking_export_sepa Full access on banking.export.sepa model_banking_export_sepa account_payment.group_account_payment 1 1 1 1

View File

@@ -1,77 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2010-2013 Akretion (http://www.akretion.com)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
The licence is in the file __openerp__.py
-->
<openerp>
<data>
<record id="view_banking_export_sepa_form" model="ir.ui.view">
<field name="name">account.banking.export.sepa.form</field>
<field name="model">banking.export.sepa</field>
<field name="arch" type="xml">
<form string="SEPA Credit Transfer" version="7.0">
<header>
<field name="state" widget="statusbar"/>
</header>
<notebook>
<page string="General Information">
<group name="main">
<field name="total_amount" />
<field name="nb_transactions" />
<field name="batch_booking" />
<field name="charge_bearer"/>
<field name="create_date" />
<field name="file" filename="filename"/>
<field name="filename" invisible="True"/>
</group>
</page>
<page string="Payment Orders">
<field name="payment_order_ids" nolabel="1"/>
</page>
</notebook>
</form>
</field>
</record>
<record id="view_banking_export_sepa_tree" model="ir.ui.view">
<field name="name">account.banking.export.sepa.tree</field>
<field name="model">banking.export.sepa</field>
<field name="arch" type="xml">
<tree string="SEPA Credit Transfer">
<field name="filename"/>
<field name="create_date"/>
<field name="nb_transactions"/>
<field name="state"/>
</tree>
</field>
</record>
<record id="action_account_banking_sepa" model="ir.actions.act_window">
<field name="name">SEPA Credit Transfer Files</field>
<field name="res_model">banking.export.sepa</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem id="menu_account_banking_sepa"
parent="account_payment.menu_main_payment"
action="action_account_banking_sepa"
sequence="15"
/>
<act_window id="act_banking_export_sepa_payment_order"
name="SEPA Credit Transfer Files"
domain="[('payment_order_ids', '=', active_id)]"
res_model="banking.export.sepa"
src_model="payment.order"
view_type="form"
view_mode="tree,form"
/>
</data>
</openerp>

View File

@@ -1,8 +1,8 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# SEPA Credit Transfer module for OpenERP
# Copyright (C) 2010-2013 Akretion (http://www.akretion.com)
# SEPA Credit Transfer module for Odoo
# Copyright (C) 2010-2015 Akretion (http://www.akretion.com)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
#
# This program is free software: you can redistribute it and/or modify
@@ -56,19 +56,14 @@ class BankingExportSepaWizard(orm.TransientModel):
"transaction charges are to be borne by the creditor. Borne "
"by debtor : all transaction charges are to be borne by the "
"debtor."),
'nb_transactions': fields.related(
'file_id', 'nb_transactions', type='integer',
'nb_transactions': fields.integer(
string='Number of Transactions', readonly=True),
'total_amount': fields.related(
'file_id', 'total_amount', type='float', string='Total Amount',
readonly=True),
'file_id': fields.many2one(
'banking.export.sepa', 'SEPA XML File', readonly=True),
'file': fields.related(
'file_id', 'file', string="File", type='binary', readonly=True),
'filename': fields.related(
'file_id', 'filename', string="Filename", type='char',
size=256, readonly=True),
'total_amount': fields.float(
string='Total Amount', readonly=True),
'file': fields.binary(
string="File", readonly=True),
'filename': fields.char(
string="Filename", readonly=True),
'payment_order_ids': fields.many2many(
'payment.order', 'wiz_sepa_payorders_rel', 'wizard_id',
'payment_order_id', 'Payment Orders', readonly=True),
@@ -132,9 +127,9 @@ class BankingExportSepaWizard(orm.TransientModel):
'name_maxsize': name_maxsize,
'convert_to_ascii': convert_to_ascii,
'payment_method': 'TRF',
'file_prefix': 'sct_',
'pain_flavor': pain_flavor,
'sepa_export': sepa_export,
'file_obj': self.pool['banking.export.sepa'],
'pain_xsd_file':
'account_banking_sepa_credit_transfer/data/%s.xsd'
% pain_flavor,
@@ -256,13 +251,6 @@ class BankingExportSepaWizard(orm.TransientModel):
cr, uid, ids, xml_root, total_amount, transactions_count_1_6,
gen_args, context=context)
def cancel_sepa(self, cr, uid, ids, context=None):
"""Cancel the SEPA file: just drop the file"""
sepa_export = self.browse(cr, uid, ids[0], context=context)
self.pool['banking.export.sepa'].unlink(
cr, uid, sepa_export.file_id.id, context=context)
return {'type': 'ir.actions.act_window_close'}
def save_sepa(self, cr, uid, ids, context=None):
"""Save the SEPA file: send the done signal to all payment
orders in the file. With the default workflow, they will
@@ -271,9 +259,13 @@ class BankingExportSepaWizard(orm.TransientModel):
reconciliation.
"""
sepa_export = self.browse(cr, uid, ids[0], context=context)
self.pool['banking.export.sepa'].write(
cr, uid, sepa_export.file_id.id, {'state': 'sent'},
context=context)
for order in sepa_export.payment_order_ids:
workflow.trg_validate(uid, 'payment.order', order.id, 'done', cr)
return {'type': 'ir.actions.act_window_close'}
self.pool['ir.attachment'].create(
cr, uid, {
'res_model': 'payment.order',
'res_id': order.id,
'name': sepa_export.filename,
'datas': sepa_export.file,
}, context=context)
return True

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2010-2013 Akretion (http://www.akretion.com)
Copyright (C) 2010-2015 Akretion (http://www.akretion.com)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
The licence is in the file __openerp__.py
-->
@@ -11,7 +11,7 @@
<field name="name">banking.export.sepa.wizard.view</field>
<field name="model">banking.export.sepa.wizard</field>
<field name="arch" type="xml">
<form string="SEPA File Generation" version="7.0">
<form string="SEPA File Generation">
<field name="state" invisible="True"/>
<group states="create">
<field name="batch_booking" />
@@ -25,9 +25,8 @@
</group>
<footer>
<button string="Generate" name="create_sepa" type="object" class="oe_highlight" states="create"/>
<button string="Cancel" special="cancel" class="oe_link" states="create"/>
<button string="Validate" name="save_sepa" type="object" class="oe_highlight" states="finish"/>
<button string="Cancel" name="cancel_sepa" type="object" class="oe_link" states="finish"/>
<button string="Cancel" special="cancel" class="oe_link"/>
</footer>
</form>
</field>