2
# -*- coding: utf-8 -*-
1
# -*- encoding: utf-8 -*-
4
2
##############################################################################
6
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
8
# $Id: make_picking.py 1070 2005-07-29 12:41:24Z nicoe $
10
# WARNING: This program as such is intended to be used by professional
11
# programmers who take the whole responsability of assessing all potential
12
# consequences resulting from its eventual inadequacies and bugs
13
# End users who are looking for a ready-to-use solution with commercial
14
# garantees and support are strongly adviced to contract a Free Software
17
# This program is Free Software; you can redistribute it and/or
18
# modify it under the terms of the GNU General Public License
19
# as published by the Free Software Foundation; either version 2
20
# of the License, or (at your option) any later version.
22
# This program is distributed in the hope that it will be useful,
23
# but WITHOUT ANY WARRANTY; without even the implied warranty of
24
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
# GNU General Public License for more details.
27
# You should have received a copy of the GNU General Public License
28
# along with this program; if not, write to the Free Software
29
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4
# OpenERP, Open Source Management Solution
5
# Copyright (c) 2009 Zikzakmedia S.L. (http://zikzakmedia.com) All Rights Reserved.
6
# Jordi Esteve <jesteve@zikzakmedia.com>
9
# This program is free software: you can redistribute it and/or modify
10
# it under the terms of the GNU General Public License as published by
11
# the Free Software Foundation, either version 3 of the License, or
12
# (at your option) any later version.
14
# This program is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU General Public License for more details.
19
# You should have received a copy of the GNU General Public License
20
# along with this program. If not, see <http://www.gnu.org/licenses/>.
31
22
##############################################################################
37
accounts_create_form = """<?xml version="1.0"?>
29
accounts_create_form = """<?xml version="1.0" encoding="utf-8"?>
38
30
<form string="Create accounts">
39
<separator string="Do you want to create accounts for the selected partners" />
31
<label string="Do you want to create accounts for the selected partners?" />
42
34
accounts_create_fields = {}
44
36
def strip0d(cadena):
45
# Elimina los ceros de la derecha en una cadena de texto de dígitos
46
return str(int(cadena[::-1]))[::-1]
37
# Elimina los ceros de la derecha en una cadena de texto de dígitos
38
return str(int(cadena[::-1]))[::-1]
48
40
def strip0i(cadena):
49
# Elimina los ceros de la izquierda en una cadena de texto de dígitos
50
return str(int(cadena))
41
# Elimina los ceros de la izquierda en una cadena de texto de dígitos
42
return str(int(cadena))
53
45
def _createAccounts(self, cr, uid, data, context):
54
partner_obj = pooler.get_pool(cr.dbname).get('res.partner')
55
account_obj = pooler.get_pool(cr.dbname).get('account.account')
56
sequence_obj = pooler.get_pool(cr.dbname).get('ir.sequence')
58
def link_account(ref,parent_code, acc_type, acc_property):
59
# parent_code: Código del padre (Ej.: 4300)
60
# type: Puede ser 'payable' o 'receivable'
61
# acc_property: 'property_account_receivable' o 'property_account_payable'
62
acc_code = parent_code + ref[2:] # acc_code es el nuevo código de subcuenta
63
args = [('code', '=', acc_code)]
64
if not account_obj.search(cr, uid, args):
65
args = [('code', '=', parent_code)]
66
parent_acc_ids = account_obj.search(cr, uid, args) # Busca id de la subcuenta padre
71
'parent_id': [(6,0,parent_acc_ids)], # acc_ids es un diccionario
73
'close_method': 'unreconciled',
74
'shortcut': strip0d(acc_code[:4]) + "." + strip0i(acc_code[-5:]),
76
acc_id = account_obj.create(cr, uid, vals)
77
vals = {acc_property: acc_id}
78
partner_obj.write(cr, uid, [partner.id], vals) # Asocia la nueva subcuenta con el partner
80
for partner in partner_obj.browse(cr, uid, data['ids'], context=context):
81
if not partner.ref or not partner.ref.strip():
82
ref = sequence_obj.get(cr, uid, 'res.partner')
84
partner_obj.write(cr, uid, [partner.id], vals)
88
if (len(ref) == 7) and (ref[2:].isdigit()):
89
for category in partner.category_id:
90
if category.name.lower() == 'cliente':
91
link_account(ref,'4300', 'receivable', 'property_account_receivable')
93
if category.name.lower() == 'proveedor':
94
link_account(ref,'4000', 'payable', 'property_account_payable')
46
partner_obj = pooler.get_pool(cr.dbname).get('res.partner')
47
account_obj = pooler.get_pool(cr.dbname).get('account.account')
48
sequence_obj = pooler.get_pool(cr.dbname).get('ir.sequence')
50
account_type_obj = pooler.get_pool(cr.dbname).get('account.account.type')
51
ids = account_type_obj.search(cr, uid, [('code', '=', 'terceros - rec')]) # Busca tipo cuenta de usuario rec
52
acc_user_type_rec = ids and ids[0]
53
ids = account_type_obj.search(cr, uid, [('code', '=', 'terceros - pay')]) # Busca tipo cuenta de usuario pay
54
acc_user_type_pay = ids and ids[0]
55
if not acc_user_type_rec and not acc_user_type_pay:
58
def link_account(ref, parent_code, acc_type, acc_user_type, acc_property):
60
parent_code: Código del padre (Ej.: 4300)
61
type: Puede ser 'payable' o 'receivable'
62
acc_property: 'property_account_receivable' o 'property_account_payable'"""
63
acc_code = parent_code + ref # acc_code es el nuevo código de subcuenta
64
args = [('code', '=', acc_code)]
65
if not account_obj.search(cr, uid, args):
70
'user_type': acc_user_type,
71
'shortcut': strip0d(acc_code[:4]) + "." + strip0i(acc_code[-5:]),
73
args = [('code', '=', parent_code)]
74
parent_acc_ids = account_obj.search(cr, uid, args) # Busca id de la subcuenta padre
76
vals['parent_id'] = parent_acc_ids[0]
77
acc_id = account_obj.create(cr, uid, vals)
78
vals = {acc_property: acc_id}
79
partner_obj.write(cr, uid, [partner.id], vals) # Asocia la nueva subcuenta con el partner
81
for partner in partner_obj.browse(cr, uid, data['ids'], context=context):
82
if not partner.customer and not partner.supplier:
84
if not partner.ref or not partner.ref.strip():
85
ref = sequence_obj.get(cr, uid, 'res.partner')
87
partner_obj.write(cr, uid, [partner.id], vals)
91
ref = ''.join([i for i in ref if i in string.digits]) # Solo nos interesa los dígitos del código
94
link_account(ref, '430', 'receivable', acc_user_type_rec, 'property_account_receivable')
97
link_account(ref, '400', 'payable', acc_user_type_pay, 'property_account_payable')
98
101
class create_accounts(wizard.interface):
102
'result' : {'type' : 'form',
103
'arch' : accounts_create_form,
104
'fields' : accounts_create_fields,
105
'state' : [('end', 'Cancel'),('create', 'Create accounts') ]}
109
'result' : {'type' : 'action',
110
'action' : _createAccounts,
114
create_accounts("partner_seq.create_accounts")
105
'result' : {'type' : 'form',
106
'arch' : accounts_create_form,
107
'fields' : accounts_create_fields,
108
'state' : [('end', 'Cancel'),('create', 'Create accounts') ]}
112
'result' : {'type' : 'action',
113
'action' : _createAccounts,
117
create_accounts("l10n_ES_partner_seq.create_accounts")