Merge lp:~yannick-buron/partner-contact-management/partner-contact-management into lp:~partner-contact-core-editors/partner-contact-management/7.0

Proposed by YannickB (YOLO consulting)
Status: Needs review
Proposed branch: lp:~yannick-buron/partner-contact-management/partner-contact-management
Merge into: lp:~partner-contact-core-editors/partner-contact-management/7.0
Diff against target: 405 lines (+368/-0)
7 files modified
base_partner_customer_fiability/__init__.py (+21/-0)
base_partner_customer_fiability/__openerp__.py (+37/-0)
base_partner_customer_fiability/base_partner_customer_fiability.py (+115/-0)
base_partner_customer_fiability/base_partner_customer_fiability_view.xml (+71/-0)
base_partner_customer_fiability/i18n/base_partner_customer_fiability.pot (+61/-0)
base_partner_customer_fiability/i18n/fr.po (+61/-0)
base_partner_customer_fiability/security/ir.model.access.csv (+2/-0)
To merge this branch: bzr merge lp:~yannick-buron/partner-contact-management/partner-contact-management
Reviewer Review Type Date Requested Status
Lorenzo Battistini (community) Needs Resubmitting
Pedro Manuel Baeza code review Needs Fixing
Review via email: mp+221742@code.launchpad.net

Description of the change

Hello everybody,

Here is a little module I use for one of my customer. It is used for managing the fiability level of the customers, to know if they will pay or not.

It's really simple, but I hope it is a good base for adding more complex features later. What do you think?

To post a comment you must log in.
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Hi, Yannick, thanks for the contribution. Some remarks:

- Please respect PEP8.
- Use orm.Model instead of osv.osv.
- Do you need all imports in base_partner_customer_fiability.py?
- Put relative imports in __init__.py.

From functional point of view:
- Why do you need a res.partner.customer.fiability model? Isn't better to have a calculated field that makes the average from invoices delays?
- I'm also worried by the overall performance of the system, due to payment_delay is not stored and general fiability of the customer changes with each paid invoice and the way you make it. You can improving calling methods with packed ids, using read for reading only one data, and so on.

Changing approach, I would put a cron job that updates once a day all the data, storing them. This only means a no real-time update, but with little differences.

Regards.

review: Needs Fixing (code review)
Revision history for this message
Lorenzo Battistini (elbati) wrote :

This project is now hosted on https://github.com/OCA/partner-contact. Please move your proposal there. This guide may help you https://github.com/OCA/maintainers-tools/wiki/How-to-move-a-Merge-Proposal-to-GitHub

review: Needs Resubmitting

Unmerged revisions

40. By yannick@yannick_buron.synerpgy.fr

[ADD] Module base_partner_customer_fiability

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'base_partner_customer_fiability'
2=== added file 'base_partner_customer_fiability/__init__.py'
3--- base_partner_customer_fiability/__init__.py 1970-01-01 00:00:00 +0000
4+++ base_partner_customer_fiability/__init__.py 2014-06-02 14:11:22 +0000
5@@ -0,0 +1,21 @@
6+# -*- coding: utf-8 -*-
7+##############################################################################
8+#
9+# Copyright (C) Yannick Buron.
10+#
11+# This program is free software: you can redistribute it and/or modify
12+# it under the terms of the GNU Affero General Public License as
13+# published by the Free Software Foundation, either version 3 of the
14+# License, or (at your option) any later version.
15+#
16+# This program is distributed in the hope that it will be useful,
17+# but WITHOUT ANY WARRANTY; without even the implied warranty of
18+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+# GNU Affero General Public License for more details.
20+#
21+# You should have received a copy of the GNU Affero General Public License
22+# along with this program. If not, see <http://www.gnu.org/licenses/>.
23+#
24+##############################################################################
25+
26+import base_partner_customer_fiability
27
28=== added file 'base_partner_customer_fiability/__openerp__.py'
29--- base_partner_customer_fiability/__openerp__.py 1970-01-01 00:00:00 +0000
30+++ base_partner_customer_fiability/__openerp__.py 2014-06-02 14:11:22 +0000
31@@ -0,0 +1,37 @@
32+# -*- coding: utf-8 -*-
33+##############################################################################
34+#
35+# Copyright Yannick Buron 2014
36+#
37+# This program is free software: you can redistribute it and/or modify
38+# it under the terms of the GNU Affero General Public License as
39+# published by the Free Software Foundation, either version 3 of the
40+# License, or (at your option) any later version.
41+#
42+# This program is distributed in the hope that it will be useful,
43+# but WITHOUT ANY WARRANTY; without even the implied warranty of
44+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45+# GNU Affero General Public License for more details.
46+#
47+# You should have received a copy of the GNU Affero General Public License
48+# along with this program. If not, see <http://www.gnu.org/licenses/>.
49+#
50+##############################################################################
51+{
52+ 'name' : 'Customer Fiability',
53+ 'version' : '1',
54+ 'author' : 'Yannick Buron',
55+ 'category' : 'Other',
56+ 'description' : """
57+This module create a status field in partner which indicate the fiability of this customer. It works by computing the average delay before the customer pay his invoices.
58+ """,
59+ 'website': 'http://www.yolo-consulting.net',
60+ 'depends' : ['account'],
61+ 'data': [
62+ 'base_partner_customer_fiability_view.xml',
63+ 'security/ir.model.access.csv'
64+ ],
65+ 'installable': True,
66+ 'auto_install': False,
67+}
68+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
69
70=== added file 'base_partner_customer_fiability/base_partner_customer_fiability.py'
71--- base_partner_customer_fiability/base_partner_customer_fiability.py 1970-01-01 00:00:00 +0000
72+++ base_partner_customer_fiability/base_partner_customer_fiability.py 2014-06-02 14:11:22 +0000
73@@ -0,0 +1,115 @@
74+##############################################################################
75+#
76+# Copyright Yannick Buron 2014
77+#
78+# This program is free software: you can redistribute it and/or modify
79+# it under the terms of the GNU Affero General Public License as
80+# published by the Free Software Foundation, either version 3 of the
81+# License, or (at your option) any later version.
82+#
83+# This program is distributed in the hope that it will be useful,
84+# but WITHOUT ANY WARRANTY; without even the implied warranty of
85+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
86+# GNU Affero General Public License for more details.
87+#
88+# You should have received a copy of the GNU Affero General Public License
89+# along with this program. If not, see <http://www.gnu.org/licenses/>.
90+#
91+##############################################################################
92+
93+
94+from datetime import datetime, timedelta
95+import logging
96+_logger = logging.getLogger(__name__)
97+
98+import openerp
99+from openerp import SUPERUSER_ID, tools
100+from openerp.osv import fields, osv
101+from openerp.tools.translate import _
102+from openerp.tools.float_utils import float_round
103+import openerp.addons.decimal_precision as dp
104+from collections import defaultdict
105+import time
106+
107+class account_invoice(osv.osv):
108+
109+ _inherit = 'account.invoice'
110+
111+ def _get_payment_delay(self, cr, uid, ids, field, args, context=None):
112+ res = {}
113+ now = datetime.now()
114+
115+ for invoice in self.browse(cr, uid, ids):
116+ res[invoice.id] = 0
117+ if invoice.date_due:
118+ date_due = datetime.strptime(invoice.date_due, "%Y-%m-%d")
119+ if invoice.state == 'paid':
120+ payment_date = False
121+ for payment in invoice.payment_ids:
122+ payment_date = payment.date
123+ if payment_date:
124+ res[invoice.id] = (datetime.strptime(payment_date, "%Y-%m-%d") - date_due).days
125+ else:
126+ res[invoice.id] = (now - date_due).days
127+ return res
128+
129+ _columns = {
130+ 'payment_delay':fields.function(_get_payment_delay, type='integer',string="Payment delay"),
131+ }
132+
133+ def confirm_paid(self, cr, uid, ids, context=None):
134+
135+ partner_obj = self.pool.get('res.partner')
136+
137+ res = super(account_invoice, self).confirm_paid(cr, uid, ids, context=context)
138+
139+ for invoice in self.browse(cr, uid, ids, context=context):
140+ partner_obj.compute_customer_fiability(cr, uid, [invoice.partner_id.id], context=context)
141+
142+ return res
143+
144+
145+
146+class res_partner_customer_fiability(osv.osv):
147+
148+ _name = 'res.partner.customer.fiability'
149+
150+ _columns = {
151+ 'name': fields.char('Fiability', size=128, required=True, translate=True),
152+ 'days': fields.integer('Days', required=True),
153+ }
154+
155+ _order = 'days'
156+
157+
158+class res_partner(osv.osv):
159+ _inherit = 'res.partner'
160+
161+ _columns = {
162+ 'customer_fiability_id': fields.many2one('res.partner.customer.fiability', 'Fiability'),
163+ 'override_customer_fiability': fields.boolean('Override fiability?')
164+ }
165+
166+ def compute_customer_fiability(self, cr, uid, ids, context=None):
167+ invoice_obj = self.pool.get('account.invoice')
168+ fiability_obj = self.pool.get('res.partner.customer.fiability')
169+
170+ for partner in self.browse(cr, uid, ids, context=context):
171+ if not partner.override_customer_fiability:
172+ invoice_ids = invoice_obj.search(cr, uid, [('partner_id','=',partner.id)], context=context)
173+ i = 0
174+ sum = 0
175+ for invoice in invoice_obj.browse(cr, uid, invoice_ids, context=context):
176+ sum += invoice.payment_delay
177+ i += 1
178+ average = 0
179+ if i:
180+ average = sum / i
181+
182+ fiability_id = False
183+ fiability_ids = fiability_obj.search(cr, uid, [], context=context)
184+ for fiability in fiability_obj.browse(cr, uid, fiability_ids, context=context):
185+ if fiability.days < average:
186+ fiability_id = fiability.id
187+
188+ self.write(cr, uid, [partner.id], {'customer_fiability_id': fiability_id}, context=context)
189
190=== added file 'base_partner_customer_fiability/base_partner_customer_fiability_view.xml'
191--- base_partner_customer_fiability/base_partner_customer_fiability_view.xml 1970-01-01 00:00:00 +0000
192+++ base_partner_customer_fiability/base_partner_customer_fiability_view.xml 2014-06-02 14:11:22 +0000
193@@ -0,0 +1,71 @@
194+<?xml version="1.0" ?>
195+<openerp>
196+ <data>
197+
198+ <record id="res_partner_customer_fiability_form" model="ir.ui.view">
199+ <field name="name">res.partner.customer.fiability.form</field>
200+ <field name="model">res.partner</field>
201+ <field name="inherit_id" ref="base.view_partner_form"/>
202+ <field name="arch" type="xml">
203+ <field name="email" position="after">
204+ <field name="customer_fiability_id" readonly="1"/>
205+ <field name="override_customer_fiability" invisible="1"/>
206+ </field>
207+ </field>
208+ </record>
209+
210+ <record id="res_partner_customer_fiability_form_manager" model="ir.ui.view">
211+ <field name="name">res.partner.customer.fiability.form.manager</field>
212+ <field name="model">res.partner</field>
213+ <field name="inherit_id" ref="res_partner_customer_fiability_form"/>
214+ <field name="groups_id" eval="[(6, 0, [ref('account.group_account_manager') ])]"/>
215+ <field name="arch" type="xml">
216+ <field name='customer_fiability_id' position="attributes">
217+ <attribute name="readonly">0</attribute>
218+ <attribute name="attrs">{'readonly': [('override_customer_fiability','=',False)]}</attribute>
219+ </field>
220+ <field name='override_customer_fiability' position="attributes">
221+ <attribute name="invisible">0</attribute>
222+ </field>
223+
224+ </field>
225+ </record>
226+
227+
228+ <record id="customer_fiability_form" model="ir.ui.view">
229+ <field name="name">customer.fiability.form</field>
230+ <field name="model">res.partner.customer.fiability</field>
231+ <field name="arch" type="xml">
232+ <form string="Fiability" version="7.0">
233+ <group col="4">
234+ <field name="name"/>
235+ <field name="days"/>
236+ </group>
237+ </form>
238+ </field>
239+ </record>
240+
241+ <record id="customer_fiability_tree" model="ir.ui.view">
242+ <field name="name">customer.fiability.tree</field>
243+ <field name="model">res.partner.customer.fiability</field>
244+ <field name="arch" type="xml">
245+ <tree string="Fiability">
246+ <field name="name"/>
247+ <field name="days"/>
248+ </tree>
249+ </field>
250+ </record>
251+
252+
253+ <record id="action_customer_fiability_tree" model="ir.actions.act_window">
254+ <field name="name">Fiability</field>
255+ <field name="res_model">res.partner.customer.fiability</field>
256+ <field name="view_type">form</field>
257+ <field name="view_mode">tree,form</field>
258+ </record>
259+
260+ <menuitem action="action_customer_fiability_tree" id="menu_action_customer_fiability_tree" parent="account.menu_configuration_misc"/>
261+
262+
263+ </data>
264+</openerp>
265
266=== added directory 'base_partner_customer_fiability/i18n'
267=== added file 'base_partner_customer_fiability/i18n/base_partner_customer_fiability.pot'
268--- base_partner_customer_fiability/i18n/base_partner_customer_fiability.pot 1970-01-01 00:00:00 +0000
269+++ base_partner_customer_fiability/i18n/base_partner_customer_fiability.pot 2014-06-02 14:11:22 +0000
270@@ -0,0 +1,61 @@
271+# Translation of OpenERP Server.
272+# This file contains the translation of the following modules:
273+# * base_partner_customer_fiability
274+#
275+msgid ""
276+msgstr ""
277+"Project-Id-Version: OpenERP Server 7.0\n"
278+"Report-Msgid-Bugs-To: \n"
279+"POT-Creation-Date: 2014-06-02 13:53+0000\n"
280+"PO-Revision-Date: 2014-06-02 13:53+0000\n"
281+"Last-Translator: <>\n"
282+"Language-Team: \n"
283+"MIME-Version: 1.0\n"
284+"Content-Type: text/plain; charset=UTF-8\n"
285+"Content-Transfer-Encoding: \n"
286+"Plural-Forms: \n"
287+
288+#. module: base_partner_customer_fiability
289+#: field:res.partner.customer.fiability,days:0
290+msgid "Days"
291+msgstr ""
292+
293+#. module: base_partner_customer_fiability
294+#: field:account.invoice,payment_delay:0
295+msgid "Payment delay"
296+msgstr ""
297+
298+#. module: base_partner_customer_fiability
299+#: model:ir.model,name:base_partner_customer_fiability.model_res_partner_customer_fiability
300+msgid "res.partner.customer.fiability"
301+msgstr ""
302+
303+#. module: base_partner_customer_fiability
304+#: model:ir.model,name:base_partner_customer_fiability.model_account_invoice
305+msgid "Invoice"
306+msgstr ""
307+
308+#. module: base_partner_customer_fiability
309+#: model:ir.model,name:base_partner_customer_fiability.model_res_partner
310+msgid "Partner"
311+msgstr ""
312+
313+#. module: base_partner_customer_fiability
314+#: field:res.partner,override_customer_fiability:0
315+msgid "Override fiability?"
316+msgstr ""
317+
318+#. module: base_partner_customer_fiability
319+#: view:res.partner:0
320+msgid "{'readonly': [('override_customer_fiability','=',False)]}"
321+msgstr ""
322+
323+#. module: base_partner_customer_fiability
324+#: model:ir.actions.act_window,name:base_partner_customer_fiability.action_customer_fiability_tree
325+#: model:ir.ui.menu,name:base_partner_customer_fiability.menu_action_customer_fiability_tree
326+#: field:res.partner,customer_fiability_id:0
327+#: view:res.partner.customer.fiability:0
328+#: field:res.partner.customer.fiability,name:0
329+msgid "Fiability"
330+msgstr ""
331+
332
333=== added file 'base_partner_customer_fiability/i18n/fr.po'
334--- base_partner_customer_fiability/i18n/fr.po 1970-01-01 00:00:00 +0000
335+++ base_partner_customer_fiability/i18n/fr.po 2014-06-02 14:11:22 +0000
336@@ -0,0 +1,61 @@
337+# Translation of OpenERP Server.
338+# This file contains the translation of the following modules:
339+# * base_partner_customer_fiability
340+#
341+msgid ""
342+msgstr ""
343+"Project-Id-Version: OpenERP Server 7.0\n"
344+"Report-Msgid-Bugs-To: \n"
345+"POT-Creation-Date: 2014-06-02 13:53+0000\n"
346+"PO-Revision-Date: 2014-06-02 13:53+0000\n"
347+"Last-Translator: <>\n"
348+"Language-Team: \n"
349+"MIME-Version: 1.0\n"
350+"Content-Type: text/plain; charset=UTF-8\n"
351+"Content-Transfer-Encoding: \n"
352+"Plural-Forms: \n"
353+
354+#. module: base_partner_customer_fiability
355+#: field:res.partner.customer.fiability,days:0
356+msgid "Days"
357+msgstr "Jours"
358+
359+#. module: base_partner_customer_fiability
360+#: field:account.invoice,payment_delay:0
361+msgid "Payment delay"
362+msgstr "Délai de paiement"
363+
364+#. module: base_partner_customer_fiability
365+#: model:ir.model,name:base_partner_customer_fiability.model_res_partner_customer_fiability
366+msgid "res.partner.customer.fiability"
367+msgstr ""
368+
369+#. module: base_partner_customer_fiability
370+#: model:ir.model,name:base_partner_customer_fiability.model_account_invoice
371+msgid "Invoice"
372+msgstr "Facture"
373+
374+#. module: base_partner_customer_fiability
375+#: model:ir.model,name:base_partner_customer_fiability.model_res_partner
376+msgid "Partner"
377+msgstr "Partenaire"
378+
379+#. module: base_partner_customer_fiability
380+#: field:res.partner,override_customer_fiability:0
381+msgid "Override fiability?"
382+msgstr "Surcharger fiabilité?"
383+
384+#. module: base_partner_customer_fiability
385+#: view:res.partner:0
386+msgid "{'readonly': [('override_customer_fiability','=',False)]}"
387+msgstr ""
388+
389+#. module: base_partner_customer_fiability
390+#: model:ir.actions.act_window,name:base_partner_customer_fiability.action_customer_fiability_tree
391+#: model:ir.ui.menu,name:base_partner_customer_fiability.menu_action_customer_fiability_tree
392+#: field:res.partner,customer_fiability_id:0
393+#: view:res.partner.customer.fiability:0
394+#: field:res.partner.customer.fiability,name:0
395+msgid "Fiability"
396+msgstr "Fiabilité"
397+
398
399=== added directory 'base_partner_customer_fiability/security'
400=== added file 'base_partner_customer_fiability/security/ir.model.access.csv'
401--- base_partner_customer_fiability/security/ir.model.access.csv 1970-01-01 00:00:00 +0000
402+++ base_partner_customer_fiability/security/ir.model.access.csv 2014-06-02 14:11:22 +0000
403@@ -0,0 +1,2 @@
404+id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
405+res_partner_customer_fiability_manager,res_partner_customer_fiability manager,model_res_partner_customer_fiability,account.group_account_manager,1,1,1,1