Merge lp:~pexego/openobject-addons/6.1-pexego-sale_commission into lp:~pexego/openobject-addons/6.1-pexego

Proposed by Javier on 2013-11-20
Status: Merged
Merged at revision: 24
Proposed branch: lp:~pexego/openobject-addons/6.1-pexego-sale_commission
Merge into: lp:~pexego/openobject-addons/6.1-pexego
Diff against target: 1235 lines (+483/-163)
15 files modified
sale_commission/__init__.py (+1/-0)
sale_commission/i18n/es.po (+125/-65)
sale_commission/invoice.py (+15/-4)
sale_commission/partner_agent.py (+1/-1)
sale_commission/product.py (+47/-0)
sale_commission/product_view.xml (+24/-0)
sale_commission/sale_order.py (+132/-20)
sale_commission/sale_order_view.xml (+13/-13)
sale_commission/saleagent.py (+4/-4)
sale_commission/saleagent_view.xml (+15/-1)
sale_commission/security/ir.model.access.csv (+3/-0)
sale_commission/settled.py (+67/-41)
sale_commission/stock_picking.py (+30/-11)
sale_commission/wizard/wizard_invoice.py (+3/-2)
sale_commission/wizard/wizard_invoice.xml (+3/-1)
To merge this branch: bzr merge lp:~pexego/openobject-addons/6.1-pexego-sale_commission
Reviewer Review Type Date Requested Status
Pexego 2013-11-20 Pending
Review via email: mp+195983@code.launchpad.net
To post a comment you must log in.
25. By Javier on 2013-11-26

[ADD]:sale_commission: Modificaciones en la generación de factura. 3 opciones de desglose

26. By Javier on 2013-11-26

[MERGE]

27. By Javier on 2013-11-27

[ADD]sale_commission: traducciones

28. By Javier on 2013-12-02

[FIX]:sale_commission: improved onchange_product_id of sale.order.line

29. By Javier on 2013-12-19

[FIX] sale_commission: Bug en product_id_change2 corregido

30. By Javier on 2013-12-31

[FIX]sale_commission: Modificaciones para que no borre los agentes de las lineas de venta en el cliente gtk

31. By Javier on 2014-01-07

[FIX]sale_commission: No permitir borrar comisiones si se han usado en algún lado, domain en los diarios para que solo muestre los de tipo compras

32. By Javier on 2014-03-13

[FIX] sale_commission: Modificacion para tener en cuenta las facturas rectificativas

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'sale_commission/__init__.py'
2--- sale_commission/__init__.py 2012-07-13 10:51:04 +0000
3+++ sale_commission/__init__.py 2014-03-13 12:35:19 +0000
4@@ -28,6 +28,7 @@
5 import sale_order
6 import stock_picking
7 import wizard
8+import product
9
10 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
11
12
13=== modified file 'sale_commission/i18n/es.po'
14--- sale_commission/i18n/es.po 2012-07-13 10:51:04 +0000
15+++ sale_commission/i18n/es.po 2014-03-13 12:35:19 +0000
16@@ -1,18 +1,18 @@
17 # Translation of OpenERP Server.
18 # This file contains the translation of the following modules:
19-# * sale_commission
20+# * sale_commission
21 #
22 msgid ""
23 msgstr ""
24-"Project-Id-Version: OpenERP Server 6.0.1\n"
25-"Report-Msgid-Bugs-To: support@openerp.com\n"
26-"POT-Creation-Date: 2011-05-02 11:44+0000\n"
27-"PO-Revision-Date: 2011-05-02 14:17+0100\n"
28-"Last-Translator: Raimon Esteve <resteve@zikzakmedia.com>\n"
29+"Project-Id-Version: OpenERP Server 6.1\n"
30+"Report-Msgid-Bugs-To: \n"
31+"POT-Creation-Date: 2013-11-27 09:45+0000\n"
32+"PO-Revision-Date: 2013-11-27 09:45+0000\n"
33+"Last-Translator: <>\n"
34 "Language-Team: \n"
35 "MIME-Version: 1.0\n"
36 "Content-Type: text/plain; charset=UTF-8\n"
37-"Content-Transfer-Encoding: 8bit\n"
38+"Content-Transfer-Encoding: \n"
39 "Plural-Forms: \n"
40
41 #. module: sale_commission
42@@ -26,6 +26,11 @@
43 msgstr "Factura Nº"
44
45 #. module: sale_commission
46+#: view:sale.agent:0
47+msgid "Saleagent"
48+msgstr "Agente"
49+
50+#. module: sale_commission
51 #: selection:sale.agent,settlement:0
52 msgid "Monthly"
53 msgstr "Mensual"
54@@ -76,11 +81,6 @@
55 msgstr "Resumen de facturas"
56
57 #. module: sale_commission
58-#: sql_constraint:sale.order:0
59-msgid "Order Reference must be unique !"
60-msgstr "¡La referencia del pedido debe ser única!"
61-
62-#. module: sale_commission
63 #: field:settlement.agent,total_sections:0
64 msgid "Total sections"
65 msgstr "Total tramos"
66@@ -96,6 +96,7 @@
67 msgstr "Informe de liquidación"
68
69 #. module: sale_commission
70+#: model:ir.actions.act_window,name:sale_commission.action_recalculate_commission
71 #: view:recalculate.commission.wizard:0
72 msgid "Recalculate agents commissions"
73 msgstr "Recalcular comisiones"
74@@ -106,6 +107,7 @@
75 msgstr "Resumen de agentes"
76
77 #. module: sale_commission
78+#: view:commission:0
79 #: view:res.partner:0
80 #: view:sale.order:0
81 msgid "Agents and Commissions"
82@@ -123,6 +125,11 @@
83 msgstr "Liquidación de agente"
84
85 #. module: sale_commission
86+#: selection:settled.invoice.wizard,mode:0
87+msgid "for each sale invoice"
88+msgstr "por cada factura de venta"
89+
90+#. module: sale_commission
91 #: view:account.invoice.line:0
92 msgid "Notes"
93 msgstr "Notas"
94@@ -133,7 +140,7 @@
95 msgstr "Anual"
96
97 #. module: sale_commission
98-#: code:addons/sale_commission/settled.py:193
99+#: code:addons/sale_commission/settled.py:190
100 #, python-format
101 msgid "Error!"
102 msgstr "Error!"
103@@ -178,6 +185,7 @@
104 #: field:invoice.line.agent,agent_id:0
105 #: field:res.partner.agent,agent_id:0
106 #: view:sale.agent:0
107+#: field:sale.line.agent,agent_id:0
108 #: field:sale.order.agent,agent_id:0
109 #: view:settled.invoice.agent:0
110 #: field:settled.invoice.agent,agent_id:0
111@@ -192,26 +200,30 @@
112 msgstr "Resumen de liquidaciones de agentes"
113
114 #. module: sale_commission
115-#: model:ir.actions.act_window,name:sale_commission.action_recalculate_commission
116-msgid "Recalculate agents commissions "
117-msgstr "Recalcular comisiones de agentes "
118-
119-#. module: sale_commission
120+#: field:commission,product_agent_ids:0
121+#: field:product.agent.commission,agent_ids:0
122+#: field:product.product,product_agent_ids:0
123 #: field:res.partner,commission_ids:0
124 #: view:res.partner.agent:0
125 #: field:sale.order,sale_agent_ids:0
126 #: view:sale.order.agent:0
127+#: field:sale.order.line,line_agent_ids:0
128 #: view:stock.picking:0
129 msgid "Agents"
130 msgstr "Agentes"
131
132 #. module: sale_commission
133-#: code:addons/sale_commission/wizard/wizard_invoice.py:55
134+#: code:addons/sale_commission/wizard/wizard_invoice.py:56
135 #, python-format
136 msgid "No Invoices were created"
137 msgstr "No se crearon facturas"
138
139 #. module: sale_commission
140+#: field:settled.invoice.wizard,mode:0
141+msgid "A line"
142+msgstr "Una linea"
143+
144+#. module: sale_commission
145 #: view:settled.wizard:0
146 msgid "Select period to Settle"
147 msgstr "Seleccionar período a liquidar"
148@@ -220,13 +232,14 @@
149 #: model:ir.model,name:sale_commission.model_res_partner
150 #: field:res.partner.agent,partner_id:0
151 #: field:sale.agent,partner_id:0
152+#: field:settled.invoice.agent,partner_id:0
153 msgid "Partner"
154 msgstr "Empresa"
155
156 #. module: sale_commission
157-#: model:ir.model,name:sale_commission.model_sale_order
158-msgid "Sales Order"
159-msgstr "Pedido de venta"
160+#: view:sale.order:0
161+msgid "Agents and Commisions"
162+msgstr "Agentes y comisiones"
163
164 #. module: sale_commission
165 #: report:settlement.report:0
166@@ -287,12 +300,6 @@
167 msgstr "Estado"
168
169 #. module: sale_commission
170-#: code:addons/sale_commission/settled.py:251
171-#, python-format
172-msgid "Error, partner fail !"
173-msgstr "Error, fallo en la empresa !"
174-
175-#. module: sale_commission
176 #: model:ir.model,name:sale_commission.model_stock_picking
177 msgid "Picking List"
178 msgstr "Albarán"
179@@ -323,6 +330,12 @@
180 msgstr "IMPORTE FACTURADO"
181
182 #. module: sale_commission
183+#: field:commission,type:0
184+#: field:sale.agent,type:0
185+msgid "Type"
186+msgstr "Tipo"
187+
188+#. module: sale_commission
189 #: view:settled.invoice.wizard:0
190 msgid "Create invoice"
191 msgstr "Crear factura"
192@@ -363,6 +376,11 @@
193 msgstr "Comisión por defecto"
194
195 #. module: sale_commission
196+#: selection:settled.invoice.wizard,mode:0
197+msgid "for each invoice line settled"
198+msgstr "por cada linea de factura liquidada"
199+
200+#. module: sale_commission
201 #: field:settlement,date:0
202 msgid "Created Date"
203 msgstr "Fecha de creación"
204@@ -378,6 +396,11 @@
205 msgstr "Código del agente"
206
207 #. module: sale_commission
208+#: view:product.product:0
209+msgid "Agents and Products"
210+msgstr "Agentes y productos"
211+
212+#. module: sale_commission
213 #: view:settled.wizard:0
214 msgid "Run Settlement Agents"
215 msgstr "Ejecutar liquidaciones de agentes"
216@@ -394,9 +417,9 @@
217 msgstr "Agentes de ventas"
218
219 #. module: sale_commission
220-#: constraint:product.product:0
221-msgid "Several dimension values for the same dimension type"
222-msgstr "Varios valores de dimensión para el tipo de la misma dimensión"
223+#: model:ir.model,name:sale_commission.model_sale_order
224+msgid "Sales Order"
225+msgstr "Pedido de venta"
226
227 #. module: sale_commission
228 #: view:commission:0
229@@ -404,15 +427,20 @@
230 msgstr "Info. general"
231
232 #. module: sale_commission
233+#: view:settlement:0
234 #: view:settlement.agent:0
235 #: field:settlement.agent,invoices:0
236 msgid "Invoices"
237 msgstr "Facturas"
238
239 #. module: sale_commission
240-#: field:product.product,commission_exent:0
241-msgid "Commission exent"
242-msgstr "Exento de comisiones"
243+#: view:account.invoice.line:0
244+#: field:account.invoice.line,commission_ids:0
245+#: view:commission:0
246+#: model:ir.ui.menu,name:sale_commission.menu_sale_commissions
247+#: model:ir.ui.menu,name:sale_commission.menu_sale_commissions_conf
248+msgid "Commissions"
249+msgstr "Comisiones"
250
251 #. module: sale_commission
252 #: model:ir.ui.menu,name:sale_commission.menu_settlement
253@@ -437,6 +465,11 @@
254 msgstr "TOTAL :"
255
256 #. module: sale_commission
257+#: report:settlement.report:0
258+msgid "PARTNER"
259+msgstr "PARTNER"
260+
261+#. module: sale_commission
262 #: model:ir.model,name:sale_commission.model_settled_invoice_wizard
263 msgid "settled.invoice.wizard"
264 msgstr "settled.invoice.wizard"
265@@ -447,9 +480,9 @@
266 msgstr "Facturado"
267
268 #. module: sale_commission
269-#: view:sale.agent:0
270-msgid "Saleagent"
271-msgstr "Agente"
272+#: field:settled.invoice.agent,invoice_number:0
273+msgid "Invoice no"
274+msgstr "Factura nº"
275
276 #. module: sale_commission
277 #: field:sale.order.agent,sale_id:0
278@@ -518,7 +551,7 @@
279 msgstr "tramos"
280
281 #. module: sale_commission
282-#: code:addons/sale_commission/settled.py:193
283+#: code:addons/sale_commission/settled.py:190
284 #, python-format
285 msgid "You can't delete it, if it isn't in cancel state."
286 msgstr "No se puede borrar. No está en estado cancelado"
287@@ -553,7 +586,17 @@
288 msgstr "settled.wizard"
289
290 #. module: sale_commission
291-#: code:addons/sale_commission/wizard/wizard_invoice.py:55
292+#: selection:settled.invoice.wizard,mode:0
293+msgid "summary for each agent"
294+msgstr "resumen por cada agente"
295+
296+#. module: sale_commission
297+#: sql_constraint:stock.picking:0
298+msgid "Reference must be unique per Company!"
299+msgstr "¡La referencia debe ser única por compañía!"
300+
301+#. module: sale_commission
302+#: code:addons/sale_commission/wizard/wizard_invoice.py:56
303 #, python-format
304 msgid "Error"
305 msgstr "Error"
306@@ -564,26 +607,24 @@
307 msgstr "Entidad o empleado relacionado"
308
309 #. module: sale_commission
310-#: code:addons/sale_commission/settled.py:252
311-#, python-format
312-msgid "Agent to settle hasn't assigned partner."
313-msgstr "El agente a liquidar no tiene una empresa asignada."
314-
315-#. module: sale_commission
316 #: field:settled.invoice.agent,settlement_agent_id:0
317 msgid "Agent settl."
318 msgstr "Liq.de agente."
319
320 #. module: sale_commission
321+#: field:sale.line.agent,line_id:0
322+msgid "Sale order line"
323+msgstr "Linea del pedido"
324+
325+#. module: sale_commission
326 #: field:settlement.line,commission:0
327 msgid "Quantity"
328 msgstr "Cantidad"
329
330 #. module: sale_commission
331-#: field:commission,type:0
332-#: field:sale.agent,type:0
333-msgid "Type"
334-msgstr "Tipo"
335+#: sql_constraint:account.invoice:0
336+msgid "Invoice Number must be unique per Company!"
337+msgstr "¡El número de factura debe ser único por compañía!"
338
339 #. module: sale_commission
340 #: field:sale.agent,code:0
341@@ -617,13 +658,9 @@
342 msgstr "Factura"
343
344 #. module: sale_commission
345-#: view:account.invoice.line:0
346-#: field:account.invoice.line,commission_ids:0
347-#: view:commission:0
348-#: model:ir.ui.menu,name:sale_commission.menu_sale_commissions
349-#: model:ir.ui.menu,name:sale_commission.menu_sale_commissions_conf
350-msgid "Commissions"
351-msgstr "Comisiones"
352+#: field:product.product,commission_exent:0
353+msgid "Commission exent"
354+msgstr "Exento de comisiones"
355
356 #. module: sale_commission
357 #: view:recalculate.commission.wizard:0
358@@ -634,12 +671,18 @@
359 msgstr "Cancelar"
360
361 #. module: sale_commission
362+#: model:ir.model,name:sale_commission.model_sale_line_agent
363+msgid "sale.line.agent"
364+msgstr "sale.line.agent"
365+
366+#. module: sale_commission
367 #: help:sale.agent,partner_id:0
368 msgid "Associated partner, is necessary for income invoices."
369 msgstr "Empresa asociada, es necesario para las facturas entrantes generadas."
370
371 #. module: sale_commission
372 #: view:sale.agent:0
373+#: view:settlement:0
374 #: view:settlement.agent:0
375 #: field:settlement.agent,settlement_id:0
376 msgid "Settlement"
377@@ -651,9 +694,9 @@
378 msgstr "Retención aplicada"
379
380 #. module: sale_commission
381-#: field:settled.invoice.agent,invoice_number:0
382-msgid "Invoice no"
383-msgstr "Factura nº"
384+#: sql_constraint:sale.order:0
385+msgid "Order Reference must be unique per Company!"
386+msgstr "¡La referencia del pedido debe ser única por compañía!"
387
388 #. module: sale_commission
389 #: report:settlement.report:0
390@@ -661,9 +704,10 @@
391 msgstr "FECHA FACTURA"
392
393 #. module: sale_commission
394-#: code:addons/sale_commission/invoice.py:82
395-#: code:addons/sale_commission/partner_agent.py:80
396-#: code:addons/sale_commission/sale_order.py:67
397+#: code:addons/sale_commission/invoice.py:91
398+#: code:addons/sale_commission/partner_agent.py:81
399+#: code:addons/sale_commission/sale_order.py:68
400+#: code:addons/sale_commission/sale_order.py:152
401 #, python-format
402 msgid "Fee installments!"
403 msgstr "Fee installments!"
404@@ -679,9 +723,10 @@
405 msgstr "Líneas de detalle"
406
407 #. module: sale_commission
408-#: code:addons/sale_commission/invoice.py:84
409-#: code:addons/sale_commission/partner_agent.py:81
410-#: code:addons/sale_commission/sale_order.py:68
411+#: code:addons/sale_commission/invoice.py:93
412+#: code:addons/sale_commission/partner_agent.py:82
413+#: code:addons/sale_commission/sale_order.py:69
414+#: code:addons/sale_commission/sale_order.py:153
415 #, python-format
416 msgid "A commission has been assigned by sections that does not match that defined for the agent by default, so that these sections shall apply only on this bill."
417 msgstr "Se ha asignado una comisión por tramos que no coincide con la definida por defecto para el agente, por lo que ese tramo solo se aplica a esta factura"
418@@ -693,6 +738,7 @@
419
420 #. module: sale_commission
421 #: model:ir.model,name:sale_commission.model_product_product
422+#: field:product.agent.commission,product_id:0
423 msgid "Product"
424 msgstr "Producto"
425
426@@ -702,6 +748,12 @@
427 msgstr "Período de liquidación"
428
429 #. module: sale_commission
430+#: view:commission:0
431+#: view:product.product:0
432+msgid "Agents/Commissions"
433+msgstr "Agents/Commissions"
434+
435+#. module: sale_commission
436 #: field:sale.agent,customer:0
437 msgid "Customer"
438 msgstr "Cliente"
439@@ -758,14 +810,22 @@
440 msgstr "Importe liquidado"
441
442 #. module: sale_commission
443+#: model:ir.model,name:sale_commission.model_product_agent_commission
444+msgid "product.agent.commission"
445+msgstr "product.agent.commission"
446+
447+#. module: sale_commission
448 #: field:invoice.line.agent,commission_id:0
449+#: field:product.agent.commission,commission_id:0
450 #: field:res.partner.agent,commission_id:0
451+#: field:sale.line.agent,commission_id:0
452 #: field:sale.order.agent,commission_id:0
453 msgid "Applied commission"
454 msgstr "Comisión aplicada"
455
456 #. module: sale_commission
457 #: field:invoice.line.agent,settled:0
458+#: view:settlement:0
459 #: selection:settlement,state:0
460 msgid "Settled"
461 msgstr "Liquidado"
462
463=== modified file 'sale_commission/invoice.py'
464--- sale_commission/invoice.py 2012-07-13 10:51:04 +0000
465+++ sale_commission/invoice.py 2014-03-13 12:35:19 +0000
466@@ -31,20 +31,25 @@
467 _name = "invoice.line.agent"
468
469 _columns = {
470- 'invoice_line_id':fields.many2one('account.invoice.line', 'Invoice Line', required=True, ondelete='cascade', help=''),
471+ 'invoice_line_id':fields.many2one('account.invoice.line', 'Invoice Line', required=False, ondelete='cascade', help=''),
472 'invoice_id':fields.related('invoice_line_id', 'invoice_id', type='many2one', relation='account.invoice', string='Invoice'),
473 'invoice_date':fields.related('invoice_id',type='date_invoice', readonly=True),
474 'agent_id': fields.many2one('sale.agent', 'Agent', required=True, ondelete='cascade', help=''),
475- 'commission_id':fields.many2one('commission', 'Applied commission', required=True, ondelete='cascade', help=''),
476+ 'commission_id':fields.many2one('commission', 'Applied commission', required=True, help=''),
477 'settled':fields.boolean('Settled', readonly=True),
478 'quantity':fields.float('Settled amount')
479 }
480 _defaults = {
481 'settled': lambda *a: False,
482- 'quantity':lambda *a: 0
483 }
484
485
486+ def copy_data(self, cr, uid, id, default=None, context=None):
487+ if not default:
488+ default = {}
489+ default.update({'settled': False})
490+ return super(invoice_line_agent, self).copy_data(cr, uid, id, default, context=context)
491+
492 def calculate_commission (self, cr, uid, ids):
493 for line_agent in self.browse(cr,uid,ids):
494 if line_agent.commission_id.type == 'fijo' and line_agent.commission_id.fix_qty:
495@@ -126,9 +131,15 @@
496 def _refund_cleanup_lines(self, cr, uid, lines):
497 """ugly function to map all fields of account.invoice.line when creates refund invoice"""
498 res = super(account_invoice, self)._refund_cleanup_lines(cr, uid, lines)
499+ # import ipdb; ipdb.set_trace()
500 for line in res:
501 if 'commission_ids' in line[2]:
502- line[2]['commission_ids'] = [(6,0, line[2].get('commission_ids', [])) ]
503+ duply_ids = []
504+ for cm_id in line[2].get('commission_ids', []):
505+ dup_id = self.pool.get("invoice.line.agent").copy(cr, uid, cm_id, {'settled': False} )
506+ duply_ids.append(dup_id)
507+ # line[2]['commission_ids'] = [(6,0, line[2].get('commission_ids', [])) ]
508+ line[2]['commission_ids'] = [(6,0, duply_ids) ]
509
510 return res
511
512
513=== modified file 'sale_commission/partner_agent.py'
514--- sale_commission/partner_agent.py 2012-07-13 10:51:04 +0000
515+++ sale_commission/partner_agent.py 2014-03-13 12:35:19 +0000
516@@ -50,7 +50,7 @@
517 _columns = {
518 'partner_id':fields.many2one('res.partner', 'Partner', required=True, ondelete='cascade', help='', select=1),
519 'agent_id':fields.many2one('sale.agent', 'Agent', required=True, ondelete='cascade', help=''),
520- 'commission_id':fields.many2one('commission', 'Applied commission', required=True, ondelete='cascade', help=''),
521+ 'commission_id':fields.many2one('commission', 'Applied commission', required=True, help=''),
522 'type': fields.related('agent_id', 'type', type="selection", selection=[('asesor', 'Adviser'), ('comercial', 'Commercial')], readonly=True,
523 store={'sale.agent': (_get_partner_agents_to_update_from_sale_agents, ['type'], 10),
524 'res.partner.agent': (lambda self, cr, uid, ids, c={}: ids, None, 20)})
525
526=== added file 'sale_commission/product.py'
527--- sale_commission/product.py 1970-01-01 00:00:00 +0000
528+++ sale_commission/product.py 2014-03-13 12:35:19 +0000
529@@ -0,0 +1,47 @@
530+# -*- coding: utf-8 -*-
531+##############################################################################
532+#
533+# OpenERP, Open Source Management Solution
534+# Copyright (C) 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>). All Rights Reserved
535+# $Id$
536+#
537+# This program is free software: you can redistribute it and/or modify
538+# it under the terms of the GNU General Public License as published by
539+# the Free Software Foundation, either version 3 of the License, or
540+# (at your option) any later version.
541+#
542+# This program is distributed in the hope that it will be useful,
543+# but WITHOUT ANY WARRANTY; without even the implied warranty of
544+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
545+# GNU General Public License for more details.
546+#
547+# You should have received a copy of the GNU General Public License
548+# along with this program. If not, see <http://www.gnu.org/licenses/>.
549+#
550+##############################################################################
551+
552+"""Modificamos las ventas para incluir el comportamiento de comisiones"""
553+from osv import fields, osv
554+
555+class product_agent_commission(osv.osv):
556+ _name = "product.agent.commission"
557+ _rec_name = "commission_id"
558+
559+ _columns = {
560+ 'product_id':fields.many2one('product.product', 'Product', required=False, ondelete='cascade', help=''),
561+ 'commission_id':fields.many2one('commission', 'Applied commission', required=True, help=''),
562+ 'agent_ids':fields.many2many('sale.agent', 'product_agent_sale_agent_rel', 'product_commission_id','agent_id','Agents'),
563+ }
564+
565+product_agent_commission()
566+
567+class product_product(osv.osv):
568+
569+ _inherit = 'product.product'
570+ _columns = {
571+ 'product_agent_ids':fields.one2many('product.agent.commission', 'product_id', 'Agents')
572+ }
573+
574+
575+product_product()
576+
577
578=== modified file 'sale_commission/product_view.xml'
579--- sale_commission/product_view.xml 2012-07-13 10:51:04 +0000
580+++ sale_commission/product_view.xml 2014-03-13 12:35:19 +0000
581@@ -11,6 +11,30 @@
582 <field name="company_id" position="after">
583 <field name="commission_exent"/>
584 </field>
585+
586+ <xpath expr="/form/notebook/page[@string='Procurement &amp; Locations']/group[3]" position="after">
587+ <group colspan="2" col="2">
588+ <separator colspan="2" string="Agents/Commissions"/>
589+ <field name="product_agent_ids" nolabel="1" mode="tree,form">
590+ <tree string="Agents and Products" editable="top">
591+ <!-- <field name="agent_ids" on_change="onchange_agent_id(agent_id)"/>
592+ <field name="commission_id" on_change="onchange_commission_id(agent_id,commission_id)"/> -->
593+ <field name="agent_ids">
594+ <tree>
595+ <field name="name"/>
596+ </tree>
597+ </field>
598+ <field name="commission_id"/>
599+ </tree>
600+ <form>
601+ <field name="commission_id"/>
602+ <separator colspan="4" string="Agents/Commissions"/>
603+ <field name="agent_ids" colspan="4" nolabel="1"/>
604+
605+ </form>
606+ </field>
607+ </group>
608+ </xpath>
609 </field>
610 </record>
611
612
613=== modified file 'sale_commission/sale_order.py'
614--- sale_commission/sale_order.py 2013-11-20 16:40:20 +0000
615+++ sale_commission/sale_order.py 2014-03-13 12:35:19 +0000
616@@ -40,7 +40,7 @@
617 _columns = {
618 'sale_id':fields.many2one('sale.order', 'Sale order', required=False, ondelete='cascade', help=''),
619 'agent_id':fields.many2one('sale.agent', 'Agent', required=True, ondelete='cascade', help=''),
620- 'commission_id':fields.many2one('commission', 'Applied commission', required=True, ondelete='cascade', help=''),
621+ 'commission_id':fields.many2one('commission', 'Applied commission', required=True, help=''),
622 }
623
624 def onchange_agent_id(self, cr, uid, ids, agent_id):
625@@ -80,7 +80,6 @@
626 'sale_agent_ids':fields.one2many('sale.order.agent', 'sale_id', 'Agents', states={'draft': [('readonly', False)]})
627 }
628
629-
630 def onchange_partner_id(self, cr, uid, ids, part):
631 """heredamos el evento de cambio del campo partner_id para actualizar el campo agent_id"""
632 sale_agent_ids=[]
633@@ -116,36 +115,149 @@
634 self.pool.get('stock.picking').write(cr, uid, pickings, {'agent_ids': [[6, 0, agents]] })
635 return res
636
637+ def create(self, cr, uid, values, context=None):
638+ """
639+ Para que el cliente gtk no borre el agente al darle a guardar
640+ """
641+ res = super(sale_order, self).create(cr, uid, values, context=context)
642+ if 'sale_agent_ids' in values:
643+ for sale_order_agent in values['sale_agent_ids']:
644+ self.pool.get('sale.order.agent').write(cr, uid, sale_order_agent[1], {'sale_id':res})
645+ return res
646+
647 sale_order()
648
649+class sale_line_agent(osv.osv):
650+ _name = "sale.line.agent"
651+ _rec_name = "agent_id"
652+
653+ _columns = {
654+ 'line_id':fields.many2one('sale.order.line', 'Sale order line', required=False, ondelete='cascade', help=''),
655+ 'agent_id':fields.many2one('sale.agent', 'Agent', required=True, ondelete='cascade', help=''),
656+ 'commission_id':fields.many2one('commission', 'Applied commission', required=True, help=''),
657+ }
658+
659+ def onchange_agent_id(self, cr, uid, ids, agent_id):
660+ """al cambiar el agente cargamos sus comisión"""
661+ result = {}
662+ v = {}
663+ if agent_id:
664+ agent = self.pool.get('sale.agent').browse(cr, uid, agent_id)
665+ v['commission_id'] = agent.commission.id
666+
667+ result['value'] = v
668+ return result
669+
670+ def onchange_commission_id(self, cr, uid, ids, agent_id=False, commission_id=False):
671+ """al cambiar la comisión comprobamos la selección"""
672+ result = {}
673+
674+ if commission_id:
675+ partner_commission = self.pool.get('commission').browse(cr, uid, commission_id)
676+ if partner_commission.sections:
677+ if agent_id:
678+ agent = self.pool.get('sale.agent').browse(cr, uid, agent_id)
679+ if agent.commission.id != partner_commission.id:
680+ result['warning'] = {}
681+ result['warning']['title'] = _('Fee installments!')
682+ result['warning']['message'] = _('A commission has been assigned by sections that does not match that defined for the agent by default, so that these sections shall apply only on this bill.')
683+ return result
684+sale_line_agent()
685+
686
687 class sale_order_line(osv.osv):
688 """Modificamos las lineas ventas para incluir las comisiones en las facturas creadas desde ventas"""
689
690 _inherit = "sale.order.line"
691-
692+ _columns = {
693+ 'line_agent_ids':fields.one2many('sale.line.agent', 'line_id', 'Agents', states={'draft': [('readonly', False)]})
694+ }
695
696 def invoice_line_create(self, cr, uid, ids, context=None):
697 if context is None:
698 context = {}
699-
700+
701 res = super(sale_order_line, self).invoice_line_create(cr, uid, ids, context)
702- so_ref = self.browse(cr,uid,ids)[0].order_id
703- for so_agent_id in so_ref.sale_agent_ids:
704- inv_lines = self.pool.get('account.invoice.line').browse(cr, uid, res)
705- for inv_line in inv_lines:
706- if inv_line.product_id and inv_line.product_id.commission_exent != True:
707- vals = {
708- 'invoice_line_id': inv_line.id,
709- 'agent_id': so_agent_id.agent_id.id,
710- 'commission_id': so_agent_id.commission_id.id,
711- 'settled': False
712- }
713- line_agent_id=self.pool.get('invoice.line.agent').create(cr, uid, vals)
714- self.pool.get('invoice.line.agent').calculate_commission(cr, uid, [line_agent_id])
715+ for inv_line in self.pool.get('account.invoice.line').browse(cr, uid, res):
716+ list_ids = [x.id for x in inv_line.commission_ids]
717+ self.pool.get('invoice.line.agent').calculate_commission(cr,uid,list_ids)
718+ return res
719+
720+ def _create_invoice_line_agent(self,cr,uid,ids,agent_id,commission_id):
721+ vals = {
722+ 'agent_id' : agent_id,
723+ 'commission_id' :commission_id,
724+ 'settled': False
725+ }
726+ line_agent_id=self.pool.get('invoice.line.agent').create(cr, uid, vals)
727+ return line_agent_id
728+
729+ def _prepare_order_line_invoice_line(self, cr, uid, line, account_id=False, context=None):
730+ res = super(sale_order_line,self)._prepare_order_line_invoice_line(cr,uid,line,account_id,context)
731+ list_ids = []
732+ if not line.product_id.commission_exent:
733+ if not line.line_agent_ids: #si la linea no tiene comissiones arrastro los del pedido a la linea de factura
734+ for so_comm in line.order_id.sale_agent_ids:
735+ line_agent_id= self._create_invoice_line_agent(cr,uid,[],so_comm.agent_id.id,so_comm.commission_id.id)
736+ list_ids.append(line_agent_id)
737+
738+ else:
739+ for l_comm in line.line_agent_ids:
740+ line_agent_id= self._create_invoice_line_agent(cr,uid,[],l_comm.agent_id.id,l_comm.commission_id.id)
741+ list_ids.append(line_agent_id)
742+ res['commission_ids'] = [(6,0,list_ids)]
743+ return res
744+
745+ def _create_line_commission(self,cr,uid,ids,agent_id,commission_id):
746+ sale_line_agent = self.pool.get("sale.line.agent")
747+ vals={
748+ 'agent_id' : agent_id,
749+ 'commission_id' : commission_id
750+ }
751+ if ids:
752+ vals['line_id'] = ids[0]
753+ return sale_line_agent.create(cr,uid,vals)
754+ def product_id_change2(self, cr, uid, ids,pricelist, product, qty=0,
755+ uom=False, qty_uos=0, uos=False, name='', partner_id=False,
756+ lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False,sale_agent_ids=False,context=None):
757+ res = super(sale_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty,uom, qty_uos, uos, name, partner_id,lang, update_tax, date_order,packaging,fiscal_position,flag,context)
758+ if product:
759+ list_agent_ids = []
760+ product_obj = self.pool.get("product.product").browse(cr,uid,product)
761+ # order_obj = self.pool.get("sale.order").browse(cr,uid,context['order_id'])
762+ sale_line_agent = self.pool.get("sale.line.agent")
763+ if ids:
764+ sale_line_agent.unlink(cr,uid,sale_line_agent.search(cr,uid,[('line_id','in',ids)]))
765+ res['value']['line_agent_ids'] = []
766+ if not product_obj.commission_exent:
767+ order_comm_ids = [x[1] for x in sale_agent_ids if x[0] != 2]
768+ order_agent_ids = [ x.agent_id.id for x in self.pool.get("sale.order.agent").browse(cr,uid,order_comm_ids)]
769+ # order_agent_ids = [x.agent_id.id for x in order_obj.sale_agent_ids]
770+ dic= {}
771+ for prod_record in product_obj.product_agent_ids:
772+ if not prod_record.agent_ids: #no hay agentes especificados para la comisión: se usan los agentes del pedido
773+ for agent_id in order_agent_ids:
774+ if agent_id not in dic:
775+ dic[agent_id] = prod_record.commission_id.id
776+ else:
777+ for agent_id in prod_record.agent_ids:
778+ if agent_id.id in order_agent_ids:
779+ dic[agent_id.id] = prod_record.commission_id.id
780+
781+ for k in dic:
782+ line_agent_id = self._create_line_commission(cr,uid,ids,k,dic[k])
783+ list_agent_ids.append(int(line_agent_id))
784+ res['value']['line_agent_ids'] = list_agent_ids
785+ return res
786+
787+ def create(self, cr, uid, values, context=None):
788+ """
789+ Para que el cliente gtk no borre el agente de la linea al darle a guardar
790+ """
791+ res = super(sale_order_line, self).create(cr, uid, values, context=context)
792+ if 'line_agent_ids' in values:
793+ for sale_line_agent in values['line_agent_ids']:
794+ self.pool.get('sale.line.agent').write(cr, uid, sale_line_agent[1], {'line_id':res})
795 return res
796
797 sale_order_line()
798-
799-
800-
801
802=== modified file 'sale_commission/sale_order_view.xml'
803--- sale_commission/sale_order_view.xml 2012-07-13 10:51:04 +0000
804+++ sale_commission/sale_order_view.xml 2014-03-13 12:35:19 +0000
805@@ -2,19 +2,6 @@
806 <openerp>
807 <data>
808
809- <!--record id="view_order_comm_tree" model="ir.ui.view">
810- <field name="name">sale.order.comm.tree</field>
811- <field name="model">sale.order</field>
812- <field name="inherit_id" ref="sale.view_order_tree"/>
813- <field name="type">tree</field>
814- <field name="arch" type="xml">
815- <field name="partner_shipping_id" position="after">
816- <field name="agent_code" select="2"/>
817- <field name="country" select="2"/>
818- </field>
819- </field>
820- </record-->
821-
822 <record id="view_order_agent_form_inherit" model="ir.ui.view">
823 <field name="name">sale.agent.order.inherit.form</field>
824 <field name="model">sale.order</field>
825@@ -32,6 +19,19 @@
826 </field>
827 </group>
828 </field>
829+ <xpath expr="//field[@name='order_line']/form/notebook/page[@string='History']" position="after">
830+ <page string='Agents and Commisions'>
831+ <field name="line_agent_ids" nolabel="1" colspan="4">
832+ <tree string="Agents and Commissions" editable="top">
833+ <field name="agent_id" on_change="onchange_agent_id(agent_id)" />
834+ <field name="commission_id" on_change="onchange_commission_id(agent_id,commission_id)"/>
835+ </tree>
836+ </field>
837+ </page>
838+ </xpath>
839+ <xpath expr="//field[@name='order_line']/form/notebook/page[@string='Order Line']/group[1]/field[@name='product_id']" position="replace">
840+ <field colspan="3" context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom, 'force_product_uom': True,'order_id': parent.id,'sale_agent_ids': parent.sale_agent_ids}" name="product_id" on_change="product_id_change2(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,product_uos,name,parent.partner_id, False, True, parent.date_order, product_packaging, parent.fiscal_position, False,parent.sale_agent_ids,context)"/>
841+ </xpath>
842 </field>
843 </record>
844
845
846=== modified file 'sale_commission/saleagent.py'
847--- sale_commission/saleagent.py 2012-07-13 10:51:04 +0000
848+++ sale_commission/saleagent.py 2014-03-13 12:35:19 +0000
849@@ -32,7 +32,8 @@
850 'name': fields.char('Name', size=64, required=True),
851 'type': fields.selection((('fijo', 'Fix percentage'), ('tramos', 'By sections')), 'Type', required=True),
852 'fix_qty': fields.float('Fix Percentage'),
853- 'sections': fields.one2many('commission.section', 'commission_id', 'Sections')
854+ 'sections': fields.one2many('commission.section', 'commission_id', 'Sections'),
855+ 'product_agent_ids':fields.one2many('product.agent.commission', 'commission_id', 'Agents')
856 }
857 _defaults = {
858 'type' : lambda *a: 'fijo',
859@@ -40,9 +41,8 @@
860
861 def calcula_tramos(self, cr, uid, ids, base):
862 commission = self.browse(cr, uid, ids)[0]
863- #Cálculo de tramos
864 for section in commission.sections:
865- if base >= section.commission_from and (base < section.commission_until or section.commission_until == 0):
866+ if abs(base) >= section.commission_from and (abs(base) < section.commission_until or section.commission_until == 0):
867 res = base * section.percent / 100.0
868 return res
869 return 0.0
870@@ -59,7 +59,7 @@
871 'commission_from': fields.float('From'),
872 'commission_until': fields.float('Until'),
873 'percent': fields.float('Percent'),
874- 'commission_id': fields.many2one('commission', 'Commission')
875+ 'commission_id': fields.many2one('commission', 'Commission', required=True)
876
877 }
878
879
880=== modified file 'sale_commission/saleagent_view.xml'
881--- sale_commission/saleagent_view.xml 2012-07-13 10:51:04 +0000
882+++ sale_commission/saleagent_view.xml 2014-03-13 12:35:19 +0000
883@@ -128,7 +128,21 @@
884 </tree>
885 </field>
886 </group>
887-
888+ <field name="product_agent_ids" nolabel="1" colspan="4">
889+ <tree string="Agents and Commissions" editable="top">
890+ <field name="agent_ids">
891+ <tree>
892+ <field name="name"/>
893+ </tree>
894+ </field>
895+ <field name="product_id"/>
896+ </tree>
897+ <form>
898+ <field name="product_id"/>
899+ <separator colspan="4" string="Agents/Commissions"/>
900+ <field name="agent_ids" colspan="4" nolabel="1"/>
901+ </form>
902+ </field>
903 </form>
904 </field>
905 </record>
906
907=== modified file 'sale_commission/security/ir.model.access.csv'
908--- sale_commission/security/ir.model.access.csv 2012-07-13 10:51:04 +0000
909+++ sale_commission/security/ir.model.access.csv 2014-03-13 12:35:19 +0000
910@@ -26,3 +26,6 @@
911 "access_settled_invoice_agent_salesman","access_settled_invoice_agent_salesman","model_settled_invoice_agent","base.group_sale_salesman",1,0,0,0
912 "access_settled_invoice_agent_sale_manager","access_settled_invoice_agent_sale_manager","model_settled_invoice_agent","base.group_sale_manager",1,1,1,1
913 "access_settled_invoice_agent_partner_manager","access_settled_invoice_agent_partner_manager","model_settled_invoice_agent","base.group_partner_manager",1,0,0,0
914+"access_sale_line_agent_salesman","access_sale_line_agent_salesman","model_sale_line_agent","base.group_sale_salesman",1,1,1,1
915+"access_product_agent_commission_salesman","access_product_agent_commission_salesman","model_product_agent_commission","base.group_sale_salesman",1,0,0,0
916+"access_product_agent_commission_sale_manager","access_product_agent_commission_sale_manager","model_product_agent_commission","base.group_sale_manager",1,1,1,1
917\ No newline at end of file
918
919=== modified file 'sale_commission/settled.py'
920--- sale_commission/settled.py 2013-10-16 10:36:21 +0000
921+++ sale_commission/settled.py 2014-03-13 12:35:19 +0000
922@@ -94,14 +94,13 @@
923 'INNER JOIN invoice_line_agent ON invoice_line_agent.invoice_line_id=account_invoice_line.id ' \
924 'INNER JOIN account_invoice ON account_invoice_line.invoice_id = account_invoice.id ' \
925 'WHERE invoice_line_agent.agent_id in (' + ",".join(map(str, context['active_ids'])) + ') AND invoice_line_agent.settled=False ' \
926- 'AND account_invoice.state<>\'draft\' AND account_invoice.type=\'out_invoice\''\
927+ 'AND account_invoice.state not in (\'draft\',\'cancel\') AND account_invoice.type in (\'out_invoice\',\'out_refund\')'\
928 'AND account_invoice.date_invoice >= \'' + o.date_from + '\' AND account_invoice.date_invoice <= \'' + o.date_to +'\''\
929 ' AND account_invoice.company_id = ' + str(user.company_id.id)
930
931 cr.execute(sql)
932 res = cr.fetchall()
933 inv_line_agent_ids = [x[0] for x in res]
934-
935 self.pool.get ('invoice.line.agent').calculate_commission( cr, uid, inv_line_agent_ids)
936
937
938@@ -141,13 +140,13 @@
939 'state': lambda *a: 'settled'
940 }
941
942- def action_invoice_create(self, cursor, user, ids, journal_id, product_id, context=None):
943+ def action_invoice_create(self, cursor, user, ids, journal_id, product_id,mode,context=None):
944
945 agents_pool=self.pool.get('settlement.agent')
946 res={}
947 for settlement in self.browse(cursor, user, ids, context=context):
948 settlement_agent_ids = map(lambda x: x.id, settlement.settlement_agent_id)
949- invoices_agent = agents_pool.action_invoice_create(cursor, user, settlement_agent_ids, journal_id, product_id)
950+ invoices_agent = agents_pool.action_invoice_create(cursor, user, settlement_agent_ids, journal_id, product_id,mode)
951
952 res[settlement.id] = invoices_agent.values()
953 return res
954@@ -198,7 +197,7 @@
955 """Liquidaciones de Agentes"""
956
957 _name = 'settlement.agent'
958-
959+ _rec_name = 'agent_id'
960 def _invoice_line_hook(self, cursor, user, move_line, invoice_line_id):
961 '''Call after the creation of the invoice line'''
962 return
963@@ -232,7 +231,7 @@
964 return False
965
966
967- def action_invoice_create(self, cursor, user, ids, journal_id, product_id, context=None):
968+ def action_invoice_create(self, cursor, user, ids, journal_id, product_id,mode,context=None):
969 '''Return ids of created invoices for the settlements'''
970
971 invoice_obj = self.pool.get('account.invoice')
972@@ -241,12 +240,12 @@
973 res = {}
974
975 for settlement in self.browse(cursor, user, ids, context=context):
976-
977+ if (not settlement.total_sections) and (not settlement.total):
978+ continue
979 payment_term_id = False
980 partner = settlement.agent_id and settlement.agent_id.partner_id
981 if not partner:
982- raise osv.except_osv(_('Error, partner fail !'),
983- _('Agent to settle hasn\'t assigned partner.'))
984+ continue
985
986 #El tipo es de facura de proveedor
987 account_id = partner.property_account_payable.id
988@@ -299,31 +298,50 @@
989 )
990 else:
991 tax_ids = map(lambda x: x.id, taxes)
992- for invoice in settlement.invoices:
993- origin = invoice.invoice_number
994- name = invoice.invoice_number
995- price_unit = invoice.settled_amount
996- discount = 0
997-
998- #set UoS if it's a sale and the picking doesn't have one
999- uos_id = False
1000-
1001- account_id = self.pool.get('account.fiscal.position').map_account(cursor, user, partner.property_account_position, account_id)
1002+
1003+ account_id = self.pool.get('account.fiscal.position').map_account(cursor, user, partner.property_account_position, account_id)
1004+ uos_id = False #set UoS if it's a sale and the picking doesn't have one
1005+ if mode == 'invoice':
1006+ for invoice in settlement.invoices:
1007+ invoice_line_id = invoice_line_obj.create(cursor, user, {
1008+ 'name': invoice.invoice_number,
1009+ 'origin': invoice.invoice_number,
1010+ 'invoice_id': invoice_id,
1011+ 'uos_id': uos_id,
1012+ 'product_id': product.id,
1013+ 'account_id': account_id,
1014+ 'price_unit': invoice.settled_amount,
1015+ 'discount': 0,
1016+ 'quantity': 1,
1017+ 'invoice_line_tax_id': [(6, 0, tax_ids)],
1018+ }, context=context)
1019+ elif mode == 'line':
1020+ for line in settlement.lines:
1021+ invoice_line_id = invoice_line_obj.create(cursor, user, {
1022+ 'name': line.invoice_id.number,
1023+ 'origin': line.invoice_id.number,
1024+ 'invoice_id': invoice_id,
1025+ 'uos_id': uos_id,
1026+ 'product_id': product.id,
1027+ 'account_id': account_id,
1028+ 'price_unit': line.commission,
1029+ 'discount': 0,
1030+ 'quantity': 1,
1031+ 'invoice_line_tax_id': [(6, 0, tax_ids)],
1032+ }, context=context)
1033+ elif mode == 'agent':
1034 invoice_line_id = invoice_line_obj.create(cursor, user, {
1035- 'name': name,
1036- 'origin': origin,
1037- 'invoice_id': invoice_id,
1038- 'uos_id': uos_id,
1039- 'product_id': product.id,
1040- 'account_id': account_id,
1041- 'price_unit': price_unit,
1042- 'discount': discount,
1043- 'quantity': 1,
1044- 'invoice_line_tax_id': [(6, 0, tax_ids)],
1045- #'account_analytic_id': account_analytic_id,
1046- }, context=context)
1047- self._invoice_line_hook(cursor, user, invoice, invoice_line_id)
1048-
1049+ 'name': settlement.settlement_id.name or '',
1050+ 'origin': settlement.settlement_id.name or '',
1051+ 'invoice_id': invoice_id,
1052+ 'uos_id': uos_id,
1053+ 'product_id': product.id,
1054+ 'account_id': account_id,
1055+ 'price_unit': settlement.total,
1056+ 'discount': 0,
1057+ 'quantity': 1,
1058+ 'invoice_line_tax_id': [(6, 0, tax_ids)],
1059+ }, context=context)
1060 invoice_obj.button_compute(cursor, user, [invoice_id], context=context,
1061 set_total=(type in ('in_invoice', 'in_refund')))
1062 self._invoice_hook(cursor, user, settlement, invoice_id)
1063@@ -338,7 +356,7 @@
1064 'INNER JOIN invoice_line_agent ON invoice_line_agent.invoice_line_id=account_invoice_line.id ' \
1065 'INNER JOIN account_invoice ON account_invoice_line.invoice_id = account_invoice.id ' \
1066 'WHERE invoice_line_agent.agent_id=' + str(set_agent.agent_id.id) + ' AND invoice_line_agent.settled=True ' \
1067- 'AND account_invoice.state<>\'draft\' AND account_invoice.type=\'out_invoice\''\
1068+ 'AND account_invoice.state not in (\'draft\',\'cancel\') AND account_invoice.type=\'out_invoice\''\
1069 'AND account_invoice.date_invoice >= \'' + date_from + '\' AND account_invoice.date_invoice <= \'' + date_to +'\''\
1070 ' AND account_invoice.company_id = ' + str(user.company_id.id)
1071
1072@@ -352,13 +370,14 @@
1073 'INNER JOIN invoice_line_agent ON invoice_line_agent.invoice_line_id=account_invoice_line.id ' \
1074 'INNER JOIN account_invoice ON account_invoice_line.invoice_id = account_invoice.id ' \
1075 'WHERE invoice_line_agent.agent_id=' + str(set_agent.agent_id.id) + ' AND invoice_line_agent.settled=False ' \
1076- 'AND account_invoice.state<>\'draft\' AND account_invoice.type=\'out_invoice\''\
1077+ 'AND account_invoice.state not in (\'draft\',\'cancel\') AND account_invoice.type in (\'out_invoice\',\'out_refund\')'\
1078 'AND account_invoice.date_invoice >= \'' + date_from + '\' AND account_invoice.date_invoice <= \'' + date_to +'\''\
1079 ' AND account_invoice.company_id = ' + str(user.company_id.id)
1080
1081 cr.execute(sql)
1082 res = cr.fetchall()
1083 inv_line_ids = [x[0] for x in res]
1084+
1085 total_per = 0
1086 total_sections = 0
1087 total = 0
1088@@ -380,14 +399,17 @@
1089 if line.commission_id.type == "tramos":
1090 if line.invoice_line_id.product_id.commission_exent != True:
1091 # Hacemos un agregado de la base de cálculo agrupándolo por las distintas comisiones en tramos que tenga el agente asignadas
1092+ if line.invoice_line_id.invoice_id.type == 'out_refund':
1093+ sign_price = - line.invoice_line_id.price_subtotal
1094+ else:
1095+ sign_price = line.invoice_line_id.price_subtotal
1096+
1097 if line.commission_id.id in sections:
1098- sections[line.commission_id.id]['base'] = sections[line.commission_id.id]['base'] + line.invoice_line_id.price_subtotal
1099+ sections[line.commission_id.id]['base'] = sections[line.commission_id.id]['base'] + sign_price
1100 sections[line.commission_id.id]['lines'].append(line) # Añade la línea de la que se añade esta base para el cálculo por tramos
1101 else:
1102- sections[line.commission_id.id] = {'type': line.commission_id, 'base':line.invoice_line_id.price_subtotal, 'lines':[line]}
1103-
1104+ sections[line.commission_id.id] = {'type': line.commission_id, 'base':sign_price, 'lines':[line]}
1105 #Tramos para cada tipo de comisión creados
1106-
1107 for tramo in sections:
1108 #Cálculo de la comisión para cada tramo
1109 sections[tramo].update({'commission': sections[tramo]['type'].calcula_tramos(sections[tramo]['base'])})
1110@@ -395,7 +417,7 @@
1111 # reparto de la comisión para cada linea
1112
1113 for linea_tramo in sections[tramo]['lines']:
1114- com_por_linea = sections[tramo]['commission']* (linea_tramo.invoice_line_id.price_subtotal/sections[tramo]['base'])
1115+ com_por_linea = sections[tramo]['commission']* (linea_tramo.invoice_line_id.price_subtotal/(abs(sections[tramo]['base']) or 1.0))
1116 linea_tramo.write({'commission':com_por_linea})
1117 inv_ag_ids = self.pool.get('invoice.line.agent').search(cr, uid, [('invoice_line_id', '=', linea_tramo.invoice_line_id.id), ('agent_id', '=', set_agent.agent_id.id)])
1118 self.pool.get('invoice.line.agent').write(cr, uid, inv_ag_ids, {'settled': True, 'quantity': com_por_linea})
1119@@ -438,7 +460,11 @@
1120 invoice_line_amount = line.invoice_line_id.price_subtotal
1121 if commission_app.type=="fijo":
1122 commission_per = commission_app.fix_qty
1123- amount = amount + line.invoice_line_id.price_subtotal * float(commission_per) / 100
1124+ # Para tener en cuenta las rectificativas
1125+ if line.invoice_line_id.invoice_id.type == 'out_refund':
1126+ amount = amount - line.invoice_line_id.price_subtotal * float(commission_per) / 100
1127+ else:
1128+ amount = amount + line.invoice_line_id.price_subtotal * float(commission_per) / 100
1129
1130 elif commission_app.type=="tramos":
1131 invoice_line_amount = 0
1132
1133=== modified file 'sale_commission/stock_picking.py'
1134--- sale_commission/stock_picking.py 2012-07-13 10:51:04 +0000
1135+++ sale_commission/stock_picking.py 2014-03-13 12:35:19 +0000
1136@@ -44,22 +44,41 @@
1137 'agent_ids':fields.many2many('sale.agent','sale_agent_clinic_rel', 'agent_id', 'clinic_id', 'Agentes' )
1138 }
1139
1140+ def _create_invoice_line_agent(self,cr,uid,ids,agent_id,commission_id,invoice_line_id):
1141+ vals = {
1142+ 'agent_id' : agent_id,
1143+ 'commission_id' : commission_id,
1144+ 'settled': False,
1145+ 'invoice_line_id' : invoice_line_id
1146+ }
1147+ line_agent_id=self.pool.get('invoice.line.agent').create(cr, uid, vals)
1148+ self.pool.get('invoice.line.agent').calculate_commission(cr, uid, [line_agent_id])
1149+ return line_agent_id
1150+
1151 def _invoice_line_hook(self, cursor, user, move_line, invoice_line_id):
1152 '''Call after the creation of the invoice line'''
1153 super(stock_picking, self)._invoice_line_hook(cursor, user, move_line, invoice_line_id)
1154-
1155+ # import ipdb; ipdb.set_trace()
1156 if move_line and move_line.sale_line_id and move_line.sale_line_id.product_id.commission_exent != True :
1157 so_ref = move_line.sale_line_id.order_id
1158- for so_agent_id in so_ref.sale_agent_ids:
1159- vals = {
1160- 'invoice_line_id': invoice_line_id,
1161- 'agent_id': so_agent_id.agent_id.id,
1162- 'commission_id': so_agent_id.commission_id.id,
1163- 'settled': False
1164- }
1165-
1166- line_agent_id=self.pool.get('invoice.line.agent').create(cursor, user, vals)
1167- self.pool.get('invoice.line.agent').calculate_commission(cursor, user, [line_agent_id])
1168+ line = move_line.sale_line_id
1169+ if not line.line_agent_ids: #si la linea no tiene comissiones arrastro los del pedido a la linea de factura
1170+ for so_comm in line.order_id.sale_agent_ids:
1171+ line_agent_id= self._create_invoice_line_agent(cursor,user,[],so_comm.agent_id.id,so_comm.commission_id.id,invoice_line_id)
1172+ else:
1173+ for l_comm in line.line_agent_ids:
1174+ line_agent_id= self._create_invoice_line_agent(cursor,user,[],l_comm.agent_id.id,l_comm.commission_id.id,invoice_line_id)
1175+
1176+ # for so_agent_id in so_ref.sale_agent_ids:
1177+ # vals = {
1178+ # 'invoice_line_id': invoice_line_id,
1179+ # 'agent_id': so_agent_id.agent_id.id,
1180+ # 'commission_id': so_agent_id.commission_id.id,
1181+ # 'settled': False
1182+ # }
1183+
1184+ # line_agent_id=self.pool.get('invoice.line.agent').create(cursor, user, vals)
1185+ # self.pool.get('invoice.line.agent').calculate_commission(cursor, user, [line_agent_id])
1186 return
1187
1188 stock_picking()
1189\ No newline at end of file
1190
1191=== modified file 'sale_commission/wizard/wizard_invoice.py'
1192--- sale_commission/wizard/wizard_invoice.py 2012-07-13 10:51:04 +0000
1193+++ sale_commission/wizard/wizard_invoice.py 2014-03-13 12:35:19 +0000
1194@@ -30,6 +30,7 @@
1195 _columns = {
1196 'journal_id':fields.many2one('account.journal', 'Target journal', required=True, select=1),
1197 'product_id':fields.many2one('product.product', 'Product for account', required=True, select=1),
1198+ 'mode': fields.selection([('line', 'for each invoice line settled'),('invoice','for each sale invoice'),('agent','summary for each agent')], 'A line', required=True),
1199 }
1200 _defaults = {
1201 }
1202@@ -39,13 +40,13 @@
1203 def create_invoice(self, cr, uid, ids, context=None):
1204 if context is None:
1205 context = {}
1206-
1207+ # import ipdb; ipdb.set_trace()
1208 data_pool = self.pool.get('ir.model.data')
1209 settlement_obj = self.pool.get('settlement')
1210
1211 for o in self.browse(cr, uid, ids, context=context):
1212 res = settlement_obj.action_invoice_create(cr, uid, context['active_ids'],
1213- journal_id=o.journal_id.id, product_id=o.product_id.id, context=context)
1214+ journal_id=o.journal_id.id, product_id=o.product_id.id,mode=o.mode,context=context)
1215
1216 invoice_ids = res.values()
1217
1218
1219=== modified file 'sale_commission/wizard/wizard_invoice.xml'
1220--- sale_commission/wizard/wizard_invoice.xml 2012-07-13 10:51:04 +0000
1221+++ sale_commission/wizard/wizard_invoice.xml 2014-03-13 12:35:19 +0000
1222@@ -8,10 +8,12 @@
1223 <field name="arch" type="xml">
1224 <form string="Create invoices">
1225 <separator colspan="4" string="Create invoice" />
1226- <field name="journal_id"/>
1227+ <field name="journal_id" domain="[('type','=','purchase')]"/>
1228 <newline/>
1229 <field name="product_id"/>
1230 <newline/>
1231+ <field name="mode"/>
1232+ <newline/>
1233 <button special="cancel" string="_Cancel" icon='gtk-cancel'/>
1234 <button name="create_invoice" string="Create" type="object" icon="terp-gtk-go-back-rtl"/>
1235 </form>

Subscribers

People subscribed via source and target branches