-
Notifications
You must be signed in to change notification settings - Fork 4
/
20_script_reprise_lettrage_411_pos
148 lines (126 loc) · 6.94 KB
/
20_script_reprise_lettrage_411_pos
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#! /usr/bin/env python
# -*- encoding: utf-8 -*-
import erppeek
import sys
#from config_prod import odoo_configuration_user
from config_test import odoo_configuration_user
import datetime
import re
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
###############################################################################
# Odoo Connection
###############################################################################
def init_openerp(url, login, password, database):
openerp = erppeek.Client(url)
uid = openerp.login(login, password=password, database=database)
user = openerp.ResUsers.browse(uid)
tz = user.tz
return openerp, uid, tz
openerp, uid, tz = init_openerp(
odoo_configuration_user['url'],
odoo_configuration_user['login'],
odoo_configuration_user['password'],
odoo_configuration_user['database'])
##################################################################
########## SET LOGGER ##########
##################################################################
class Logger(object):
def __init__(self, filename='Default.log'):
self.terminal = sys.stdout
self.log = open(filename, "a")
def write(self, message):
#message = message.decode('utf-8')
self.terminal.write(message)
self.log.write(message)
log_file = 'log_' + datetime.datetime.now().strftime("%Y-%m-%d %H_%M_%s")+'.log'
print "stdout = ./"+log_file
sys.stdout = Logger(log_file)
print datetime.datetime.now().strftime("%Y-%m-%d %H_%M_%s")
###############################################################################
# Script
###############################################################################
id_account_411000 = 277 #411100 Clients - Vtes - Collectif
def reconcile_411_pos(date_debut):
# CAS NON GERES :
# - plusieurs passagaes en caisse dans la même journée pour un mm membre
# - écritures de retour (car date de paiement différente de la date de la session) => à lettrer à la main
# - écritures sans partenaires (antérieures à l'ouverture du magasin) => à lettrer globalement sur un compte poubelle
# PERF
# sur les 300 premières ventes : 14:37:15 => 15:02:12 soit 24min57s
# 4.99s/vente soit 156h soit 6,5 jours pour traiter les 112687 ventes
# 11 "aucune possibilité" soit mois de 4%
# sur les 736 premières ventes : 14:37:15 => 15:37:15 => soit 60 minutes
# 4,89s/vente soit 6,38 jours pour traiter les 112687 ventes
# 23 "aucune possibilité" soit 3.13%
debit_moves = openerp.AccountMoveLine.browse([
('date', '<', date_debut),
('reconciled', '=', False),
('account_id', '=', id_account_411000),
# ('ref', 'like', "POS%"),
('partner_id', '!=', None),
('debit', '>', 0),
('credit', '=', 0)],order='id')
ok_plusieurs_possibilites = 0
ko_plusieurs_possibilites = 0
ko_aucune_possibilite = 0
exactement_une_possibilite = 0
total_a_lettrer = len(debit_moves)
i = 0
for debit_to_reconcile in debit_moves:
i += 1
print "============================"
print "Avancement : ", i, " / ", total_a_lettrer
print " ko_aucune_possibilite = ", ko_aucune_possibilite
print " ko_plusieurs_possibilites = ", ko_plusieurs_possibilites
print " ok_plusieurs_possibilites = ", ok_plusieurs_possibilites
print " exactement_une_possibilite = ", exactement_une_possibilite
print " %%%%%%%% "
print " Ecriture de vente (debit 411) : ", debit_to_reconcile.id, debit_to_reconcile.name, debit_to_reconcile.date, debit_to_reconcile.partner_id.name, debit_to_reconcile.debit, debit_to_reconcile.credit, debit_to_reconcile.name, debit_to_reconcile.ref, debit_to_reconcile.account_id.name
line_to_reconcil = [debit_to_reconcile.id]
search_critera = [
('reconciled', '=', False),
('account_id', '=', id_account_411000),
# ('ref', 'like', "POS%"),
('debit', '=', 0),
# ('credit', '>', round(debit_to_reconcile.debit-0.01,2)),
# ('credit', '<', round(debit_to_reconcile.debit+0.01,2)),
('date','=',debit_to_reconcile.date),
('partner_id','=',debit_to_reconcile.partner_id.id)]
print " Criteres de recherche de l'ecriture au crédit ", search_critera
credit_candidates = openerp.AccountMoveLine.browse(search_critera,order='id')
if len(credit_candidates) > 1:
print " => Plusieurs possibilités"
print " Nombre de lignes de paiement correspondantes : ", len(credit_candidates)
somme_credit = 0.0
for payment_moveline in credit_candidates :
somme_credit += payment_moveline.credit
line_to_reconcil.append(payment_moveline.id)
# print " Ecriture de paiement : ", payment_moveline.id, payment_moveline.name, payment_moveline.date, payment_moveline.partner_id.name, payment_moveline.debit, payment_moveline.credit, payment_moveline.name, payment_moveline.ref, payment_moveline.account_id.name
if (abs(somme_credit-debit_to_reconcile.debit)<0.01): #handle multiple payement for one pos ticket
ok_plusieurs_possibilites += 1
print " => Total des lignes de crédit du jour pour ce partner correspond"
print " ->", len(line_to_reconcil), "lignes à lettrer portant les id : ", line_to_reconcil
wizard_id = 1
r = openerp.execute_kw('account.move.line.reconcile', 'trans_rec_reconcile_full', [wizard_id], {'context': {'active_ids': line_to_reconcil}})
print r
else :
ko_plusieurs_possibilites += 1
print " => Total des lignes de crédit du jour pour ce partner au 411 != total debit"
if len(credit_candidates) == 0 :
ko_aucune_possibilite += 1
print " => Aucune possibilité"
if len(credit_candidates) == 1:
exactement_une_possibilite += 1
payment_moveline = credit_candidates[0]
print " Ecriture de paiement : ", payment_moveline.id, payment_moveline.name, payment_moveline.date, payment_moveline.partner_id.name, payment_moveline.debit, payment_moveline.credit, payment_moveline.name, payment_moveline.ref, payment_moveline.account_id.name
line_to_reconcil.append(payment_moveline.id)
print " ->", len(line_to_reconcil), "lignes à lettrer portant les id : ", line_to_reconcil
wizard_id = 1
r = openerp.execute_kw('account.move.line.reconcile', 'trans_rec_reconcile_full', [wizard_id], {'context': {'active_ids': line_to_reconcil}})
print r
# exit()
reconcile_411_pos('2018-04-17')
print "\n>>>>>>> DONE >>>>>>>>>>"
print datetime.datetime.now().strftime("%Y-%m-%d %H_%M_%s")