mirror of
https://github.com/OCA/account-reconcile.git
synced 2025-01-20 12:27:39 +02:00
[ADD] add module to improve completion from label
This commit is contained in:
committed by
Sebastien Beau
parent
e33044d520
commit
e3d452d7e9
25
account_statement_completion_label/__init__.py
Normal file
25
account_statement_completion_label/__init__.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
###############################################################################
|
||||||
|
#
|
||||||
|
# account_statement_completion_label for OpenERP
|
||||||
|
# Copyright (C) 2013 Akretion (http://www.akretion.com). All Rights Reserved
|
||||||
|
# @author Benoît GUILLOT <benoit.guillot@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/>.
|
||||||
|
#
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
import partner
|
||||||
|
import statement
|
||||||
|
|
||||||
42
account_statement_completion_label/__openerp__.py
Normal file
42
account_statement_completion_label/__openerp__.py
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
###############################################################################
|
||||||
|
#
|
||||||
|
# account_statement_completion_label for OpenERP
|
||||||
|
# Copyright (C) 2013 Akretion (http://www.akretion.com). All Rights Reserved
|
||||||
|
# @author Benoît GUILLOT <benoit.guillot@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/>.
|
||||||
|
#
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
{
|
||||||
|
'name': 'account_statement_completion_label',
|
||||||
|
'version': '0.1',
|
||||||
|
'category': 'Generic Modules/Others',
|
||||||
|
'license': 'AGPL-3',
|
||||||
|
'description': """empty""",
|
||||||
|
'author': 'Akretion',
|
||||||
|
'website': 'http://www.akretion.com/',
|
||||||
|
'depends': ['account_statement_base_completion'],
|
||||||
|
'init_xml': [],
|
||||||
|
'update_xml': [
|
||||||
|
'partner_view.xml',
|
||||||
|
'statement_view.xml',
|
||||||
|
'security/ir.model.access.csv',
|
||||||
|
],
|
||||||
|
'demo_xml': [],
|
||||||
|
'installable': True,
|
||||||
|
'active': False,
|
||||||
|
}
|
||||||
|
|
||||||
33
account_statement_completion_label/partner.py
Normal file
33
account_statement_completion_label/partner.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
###############################################################################
|
||||||
|
#
|
||||||
|
# account_statement_completion_label for OpenERP
|
||||||
|
# Copyright (C) 2013 Akretion (http://www.akretion.com). All Rights Reserved
|
||||||
|
# @author Benoît GUILLOT <benoit.guillot@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.osv import fields, orm
|
||||||
|
|
||||||
|
|
||||||
|
class res_partner(orm.Model):
|
||||||
|
_inherit = "res.partner"
|
||||||
|
|
||||||
|
_columns = {
|
||||||
|
'bank_statement_label': fields.one2many('account.statement.label',
|
||||||
|
'partner_id',
|
||||||
|
'Bank Statement Label'),
|
||||||
|
}
|
||||||
39
account_statement_completion_label/partner_view.xml
Normal file
39
account_statement_completion_label/partner_view.xml
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
account_statement_completion_label for OpenERP
|
||||||
|
Copyright (C) 2013 Akretion (http://www.akretion.com). All Rights Reserved
|
||||||
|
@author Benoît GUILLOT <benoit.guillot@akretion.com>
|
||||||
|
The licence is in the file __openerp__.py
|
||||||
|
-->
|
||||||
|
|
||||||
|
<openerp>
|
||||||
|
<data>
|
||||||
|
|
||||||
|
<!-- INHERITED VIEW FOR THE OBJECT : res_partner -->
|
||||||
|
|
||||||
|
<!-- <record id="res_partner_view_form" model="ir.ui.view">
|
||||||
|
<field name="name">account_statement_completion_label.res_partner.view_form</field>
|
||||||
|
<field name="model">res.partner</field>
|
||||||
|
<field name="inherit_id" ref="module_name_to_inherit.view_id" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="field_reference" position="after">
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="res_partner_view_tree" model="ir.ui.view">
|
||||||
|
<field name="name">account_statement_completion_label.res_partner.view_tree</field>
|
||||||
|
<field name="model">res.partner</field>
|
||||||
|
<field name="inherit_id" ref="module_name_to_inherit.view_id" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="field_reference" position="after">
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
|
||||||
|
</data>
|
||||||
|
</openerp>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||||
|
access_account_statement_label_user,account.statement.label,model_account_statement_label,account.group_account_user,1,0,0,0
|
||||||
|
access_account_statement_label_manager,account.statement.label,model_account_statement_label,account.group_account_manager,1,1,1,1
|
||||||
|
146
account_statement_completion_label/statement.py
Normal file
146
account_statement_completion_label/statement.py
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
###############################################################################
|
||||||
|
#
|
||||||
|
# account_statement_completion_label for OpenERP
|
||||||
|
# Copyright (C) 2013 Akretion (http://www.akretion.com). All Rights Reserved
|
||||||
|
# @author Benoît GUILLOT <benoit.guillot@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.osv import fields, orm
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
|
|
||||||
|
class ErrorTooManyLabel(Exception):
|
||||||
|
"""
|
||||||
|
New Exception definition that is raised when more than one label is matched by
|
||||||
|
the completion rule.
|
||||||
|
"""
|
||||||
|
def __init__(self, value):
|
||||||
|
self.value = value
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return repr(self.value)
|
||||||
|
|
||||||
|
|
||||||
|
class AccountBankSatement(orm.Model):
|
||||||
|
"""
|
||||||
|
We add a basic button and stuff to support the auto-completion
|
||||||
|
of the bank statement once line have been imported or manually fullfill.
|
||||||
|
"""
|
||||||
|
_inherit = "account.bank.statement"
|
||||||
|
|
||||||
|
def add_completion_label(self, cr, uid, ids, context=None):
|
||||||
|
model_data_obj = self.pool.get('ir.model.data')
|
||||||
|
model_data_id = model_data_obj.search(cr, uid,
|
||||||
|
[('model', '=', 'ir.ui.view'),
|
||||||
|
('name', '=', 'statement_label_wizard_view_form')
|
||||||
|
], context=context)
|
||||||
|
if model_data_id:
|
||||||
|
res_id = model_data_obj.read(cr, uid,
|
||||||
|
model_data_id,
|
||||||
|
['res_id'],
|
||||||
|
context=context)[0]['res_id']
|
||||||
|
return {
|
||||||
|
'name': 'Statement Label',
|
||||||
|
'view_type': 'form',
|
||||||
|
'view_mode': 'form',
|
||||||
|
'view_id': [res_id],
|
||||||
|
'res_model': 'account.statement.label',
|
||||||
|
'type': 'ir.actions.act_window',
|
||||||
|
'nodestroy': True,
|
||||||
|
'target': 'new',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class AccountStatementCompletionRule(orm.Model):
|
||||||
|
_inherit = "account.statement.completion.rule"
|
||||||
|
|
||||||
|
def get_from_label_and_partner_field(self, cr, uid, line_id, context=None):
|
||||||
|
"""
|
||||||
|
Match the partner based on the label field of the statement line
|
||||||
|
and the text defined in the 'bank_statement_label' field of the partner.
|
||||||
|
Remember that we can have values separated with ; Then, call the generic
|
||||||
|
get_values_for_line method to complete other values.
|
||||||
|
If more than one partner matched, raise the ErrorTooManyPartner error.
|
||||||
|
|
||||||
|
:param dict st_line: read of the concerned account.bank.statement.line
|
||||||
|
:return:
|
||||||
|
A dict of value that can be passed directly to the write method of
|
||||||
|
the statement line or {}
|
||||||
|
{'partner_id': value,
|
||||||
|
'account_id': value,
|
||||||
|
|
||||||
|
...}
|
||||||
|
"""
|
||||||
|
st_obj = self.pool.get('account.bank.statement.line')
|
||||||
|
label_obj = self.pool.get('account.statement.label')
|
||||||
|
st_line = st_obj.browse(cr, uid, line_id, context=context)
|
||||||
|
res = {}
|
||||||
|
# As we have to iterate on each partner for each line,
|
||||||
|
# we memorize the pair to avoid
|
||||||
|
# to redo computation for each line.
|
||||||
|
# Following code can be done by a single SQL query
|
||||||
|
# but this option is not really maintanable
|
||||||
|
if not context.get('label_memorizer'):
|
||||||
|
context['label_memorizer'] = defaultdict(list)
|
||||||
|
label_ids = label_obj.search(cr, uid,
|
||||||
|
['|',
|
||||||
|
('profile_id', '=', st_line.statement_id.profile_id.id),
|
||||||
|
('profile_id', '=', False)],
|
||||||
|
context=context)
|
||||||
|
for label in label_obj.browse(cr, uid, label_ids, context=context):
|
||||||
|
line_ids = st_obj.search(cr, uid,
|
||||||
|
[('statement_id', '=', st_line.statement_id.id),
|
||||||
|
('name', 'ilike', label.label),
|
||||||
|
('already_completed', '=', False)],
|
||||||
|
context=context)
|
||||||
|
import pdb;pdb.set_trace()
|
||||||
|
for line_id in line_ids:
|
||||||
|
context['label_memorizer'][line_id].append({'partner_id': label.partner_id.id,
|
||||||
|
'account_id': label.account_id.id})
|
||||||
|
if st_line['id'] in context['label_memorizer']:
|
||||||
|
label_info = context['label_memorizer'][st_line['id']]
|
||||||
|
if len(label_info) > 1:
|
||||||
|
raise ErrorTooManyPartner(_('Line named "%s" (Ref:%s) was matched by '
|
||||||
|
'more than one statement label.') %
|
||||||
|
(st_line['name'], st_line['ref']))
|
||||||
|
res['partner_id'] = label_info[0]['partner_id']
|
||||||
|
res['account_id'] = label_info[0]['account_id']
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
class AccountStatementLabel(orm.Model):
|
||||||
|
"""Create a new class to map an account statement label to a partner
|
||||||
|
and a specific account
|
||||||
|
"""
|
||||||
|
_name = "account.statement.label"
|
||||||
|
|
||||||
|
_description = "Account Statement Label"
|
||||||
|
|
||||||
|
_columns = {
|
||||||
|
'partner_id': fields.many2one('res.partner', 'Partner'),
|
||||||
|
'label': fields.char('Bank Statement Label', size=100),
|
||||||
|
'account_id': fields.many2one('account.account', 'Account',
|
||||||
|
help='Account corresponding to the label '
|
||||||
|
'for a given partner'),
|
||||||
|
'company_id': fields.many2one('res.company', 'Company'),
|
||||||
|
'profile_id': fields.many2one('account.statement.profile',
|
||||||
|
'Account Profile'),
|
||||||
|
}
|
||||||
|
|
||||||
|
def save_and_close_label(self, cr, uid, ids, context=None):
|
||||||
|
return {'type': 'ir.actions.act_window_close'}
|
||||||
88
account_statement_completion_label/statement_view.xml
Normal file
88
account_statement_completion_label/statement_view.xml
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
account_statement_completion_label for OpenERP
|
||||||
|
Copyright (C) 2013 Akretion (http://www.akretion.com). All Rights Reserved
|
||||||
|
@author Benoît GUILLOT <benoit.guillot@akretion.com>
|
||||||
|
The licence is in the file __openerp__.py
|
||||||
|
-->
|
||||||
|
|
||||||
|
<openerp>
|
||||||
|
<data>
|
||||||
|
|
||||||
|
<record id="bank_statement_view_form" model="ir.ui.view">
|
||||||
|
<field name="name">account_statement_completion_label.bank_statement.view_form</field>
|
||||||
|
<field name="model">account.bank.statement</field>
|
||||||
|
<field name="inherit_id" ref="account.view_bank_statement_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<data>
|
||||||
|
<xpath expr="/form/sheet/div[@name='import_buttons']" position="after">
|
||||||
|
<button name="add_completion_label" string="Add Completion Label"
|
||||||
|
states='draft,open' type="object" colspan="1"/>
|
||||||
|
</xpath>
|
||||||
|
</data>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="statement_label_view_form" model="ir.ui.view">
|
||||||
|
<field name="name">account.statement.label.view</field>
|
||||||
|
<field name="model">account.statement.label</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<form string="Statement Label">
|
||||||
|
<field name="label"/>
|
||||||
|
<field name="partner_id"/>
|
||||||
|
<field name="account_id"/>
|
||||||
|
<field name="profile_id"/>
|
||||||
|
<field name="company_id"/>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record model="ir.ui.view" id="statement_label_wizard_view_form">
|
||||||
|
<field name="name">account.statement.label.view.wizard</field>
|
||||||
|
<field name="model">account.statement.label</field>
|
||||||
|
<field eval="50" name="priority"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<form string="Product" version="7.0">
|
||||||
|
<group name="label">
|
||||||
|
<field name="label"/>
|
||||||
|
<field name="partner_id"/>
|
||||||
|
<field name="account_id"/>
|
||||||
|
<field name="profile_id"/>
|
||||||
|
</group>
|
||||||
|
<footer>
|
||||||
|
<button name="save_and_close_label"
|
||||||
|
string="Save and Close"
|
||||||
|
type="object" class="oe_highlight"/>
|
||||||
|
or
|
||||||
|
<button special="cancel" string="Cancel" class="oe_link"/>
|
||||||
|
</footer>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="statement_label_view_tree" model="ir.ui.view">
|
||||||
|
<field name="name">account.statement.label.view</field>
|
||||||
|
<field name="model">account.statement.label</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<tree string="Statement Label">
|
||||||
|
<field name="label"/>
|
||||||
|
<field name="partner_id"/>
|
||||||
|
<field name="account_id"/>
|
||||||
|
<field name="profile_id"/>
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="action_statement_label_tree" model="ir.actions.act_window">
|
||||||
|
<field name="name">Account Statement Label</field>
|
||||||
|
<field name="res_model">account.statement.label</field>
|
||||||
|
<field name="view_type">form</field>
|
||||||
|
<field name="view_mode">tree,form</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<menuitem string="Statement Label" action="action_statement_label_tree"
|
||||||
|
id="menu_action_statement_label_tree_menu" parent="account.menu_configuration_misc"
|
||||||
|
sequence="40"/>
|
||||||
|
|
||||||
|
</data>
|
||||||
|
</openerp>
|
||||||
Reference in New Issue
Block a user