Merge lp:~inddiana/diana-addons/nota_credito_desc_financieros into lp:diana-addons/6.0
- nota_credito_desc_financieros
- Merge into trunk-2
Proposed by
[SISB] Aryrosa Fuentes
Status: | Merged |
---|---|
Merged at revision: | 12 |
Proposed branch: | lp:~inddiana/diana-addons/nota_credito_desc_financieros |
Merge into: | lp:diana-addons/6.0 |
Diff against target: |
499 lines (+444/-0) 10 files modified
notas_de_credito/__init__.py (+4/-0) notas_de_credito/__openerp__.py (+22/-0) notas_de_credito/model/__init__.py (+21/-0) notas_de_credito/model/product_tax.py (+32/-0) notas_de_credito/security/ir.model.access.csv (+2/-0) notas_de_credito/security/nc_des_financiero_security.xml (+13/-0) notas_de_credito/view/nota_credito_desc_financiero.xml (+62/-0) notas_de_credito/wizard/__init__.py (+21/-0) notas_de_credito/wizard/nota_credito_1_x_100_wizard.py (+235/-0) notas_de_credito/wizard/nota_credito_1_x_100_wizard.xml (+32/-0) |
To merge this branch: | bzr merge lp:~inddiana/diana-addons/nota_credito_desc_financieros |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Aristóbulo Meneses | Pending | ||
Review via email: mp+161058@code.launchpad.net |
Commit message
Description of the change
[ADD] Nuevo modulo para aplicar notas de credito a descuentos financieros de 1 porciento.
Se debe comentar el constraint en presupuesto. Se debe configurar los productos, asociar al grupo la categoria de estos productos, asociar el usuario al nuevo grupo.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added directory 'notas_de_credito' | |||
2 | === added file 'notas_de_credito/__init__.py' | |||
3 | --- notas_de_credito/__init__.py 1970-01-01 00:00:00 +0000 | |||
4 | +++ notas_de_credito/__init__.py 2013-04-26 02:38:26 +0000 | |||
5 | @@ -0,0 +1,4 @@ | |||
6 | 1 | # -*- coding: utf-8 -*- | ||
7 | 2 | |||
8 | 3 | import model | ||
9 | 4 | import wizard | ||
10 | 0 | 5 | ||
11 | === added file 'notas_de_credito/__openerp__.py' | |||
12 | --- notas_de_credito/__openerp__.py 1970-01-01 00:00:00 +0000 | |||
13 | +++ notas_de_credito/__openerp__.py 2013-04-26 02:38:26 +0000 | |||
14 | @@ -0,0 +1,22 @@ | |||
15 | 1 | # -*- coding: utf-8 -*- | ||
16 | 2 | |||
17 | 3 | { | ||
18 | 4 | "name" : "Registro nota de credito por descuentos financieros", | ||
19 | 5 | "version" : "1.0", | ||
20 | 6 | "author" : "Industrias Diana C.A.", | ||
21 | 7 | "category" : "Interfaces", | ||
22 | 8 | "website" : "http://www.industriasdiana.gob.ve", | ||
23 | 9 | "depends" : ["sisb_ventas", | ||
24 | 10 | 'l10n_ve_presupuesto', | ||
25 | 11 | ], | ||
26 | 12 | "description": """Wizard para registrar nota de credito por descuentos financieros para facturas de ventas. Incluye la informacion para presupuesto.""", | ||
27 | 13 | "update_xml" : [ | ||
28 | 14 | 'security/nc_des_financiero_security.xml', | ||
29 | 15 | 'security/ir.model.access.csv', | ||
30 | 16 | 'view/nota_credito_desc_financiero.xml', | ||
31 | 17 | 'wizard/nota_credito_1_x_100_wizard.xml', | ||
32 | 18 | ], | ||
33 | 19 | "active": False, | ||
34 | 20 | "installable": True, | ||
35 | 21 | 'data' : [], | ||
36 | 22 | } | ||
37 | 0 | 23 | ||
38 | === added directory 'notas_de_credito/i18n' | |||
39 | === added directory 'notas_de_credito/model' | |||
40 | === added file 'notas_de_credito/model/__init__.py' | |||
41 | --- notas_de_credito/model/__init__.py 1970-01-01 00:00:00 +0000 | |||
42 | +++ notas_de_credito/model/__init__.py 2013-04-26 02:38:26 +0000 | |||
43 | @@ -0,0 +1,21 @@ | |||
44 | 1 | #!/usr/bin/python | ||
45 | 2 | # -*- encoding: utf-8 -*- | ||
46 | 3 | ###############Credits######################################################### | ||
47 | 4 | # Finance by: Industrias Diana, C.A. http://www.industriasdiana.gob.ve | ||
48 | 5 | ############################################################################### | ||
49 | 6 | # This program is free software: you can redistribute it and/or modify | ||
50 | 7 | # it under the terms of the GNU Affero General Public License as published by | ||
51 | 8 | # the Free Software Foundation, either version 3 of the License, or | ||
52 | 9 | # (at your option) any later version. | ||
53 | 10 | # | ||
54 | 11 | # This program is distributed in the hope that it will be useful, | ||
55 | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
56 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
57 | 14 | # GNU Affero General Public License for more details. | ||
58 | 15 | # | ||
59 | 16 | # You should have received a copy of the GNU Affero General Public License | ||
60 | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
61 | 18 | ############################################################################### | ||
62 | 19 | |||
63 | 20 | |||
64 | 21 | import product_tax | ||
65 | 0 | 22 | ||
66 | === added file 'notas_de_credito/model/product_tax.py' | |||
67 | --- notas_de_credito/model/product_tax.py 1970-01-01 00:00:00 +0000 | |||
68 | +++ notas_de_credito/model/product_tax.py 2013-04-26 02:38:26 +0000 | |||
69 | @@ -0,0 +1,32 @@ | |||
70 | 1 | # -*- coding: utf-8 -*- | ||
71 | 2 | """ | ||
72 | 3 | Módulo utilizado para configurar los productos a escoger para asociar a las notas de credito del 1 porciento segun los impuestos | ||
73 | 4 | """ | ||
74 | 5 | |||
75 | 6 | import time | ||
76 | 7 | import netsvc | ||
77 | 8 | from osv import fields, osv | ||
78 | 9 | from tools import config | ||
79 | 10 | from tools.translate import _ | ||
80 | 11 | import decimal_precision as dp | ||
81 | 12 | |||
82 | 13 | #---------------------------------------------------------- | ||
83 | 14 | # Productos tipo servicio y el impuesto asociado | ||
84 | 15 | #---------------------------------------------------------- | ||
85 | 16 | |||
86 | 17 | class nota_credito_product_tax(osv.osv): | ||
87 | 18 | _name = "nota.credito.product_tax" | ||
88 | 19 | _description = "Productos de Notas de Credito" | ||
89 | 20 | _order = "name" | ||
90 | 21 | |||
91 | 22 | _columns = { | ||
92 | 23 | 'name': fields.char('Nombre', size=64, select=True, required=True), | ||
93 | 24 | 'tax_id': fields.many2one('account.tax', 'Impuesto', required=True), | ||
94 | 25 | 'product_id': fields.many2one('product.product', 'Servicio de Descuento', required=True), | ||
95 | 26 | } | ||
96 | 27 | _sql_constraints = [ | ||
97 | 28 | ('tax_product_uniq', 'unique (tax_id, product_id)', 'The combination of tax and product must be unique !'), | ||
98 | 29 | ] | ||
99 | 30 | |||
100 | 31 | |||
101 | 32 | nota_credito_product_tax() | ||
102 | 0 | 33 | ||
103 | === added directory 'notas_de_credito/security' | |||
104 | === added file 'notas_de_credito/security/ir.model.access.csv' | |||
105 | --- notas_de_credito/security/ir.model.access.csv 1970-01-01 00:00:00 +0000 | |||
106 | +++ notas_de_credito/security/ir.model.access.csv 2013-04-26 02:38:26 +0000 | |||
107 | @@ -0,0 +1,2 @@ | |||
108 | 1 | "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" | ||
109 | 2 | "access_nc_des_financiero","nota_credito.product_tax","model_nota_credito_product_tax","group_nc_des_financiero_user",1,1,1,0 | ||
110 | 0 | 3 | ||
111 | === added file 'notas_de_credito/security/nc_des_financiero_security.xml' | |||
112 | --- notas_de_credito/security/nc_des_financiero_security.xml 1970-01-01 00:00:00 +0000 | |||
113 | +++ notas_de_credito/security/nc_des_financiero_security.xml 2013-04-26 02:38:26 +0000 | |||
114 | @@ -0,0 +1,13 @@ | |||
115 | 1 | <?xml version="1.0" encoding="utf-8"?> | ||
116 | 2 | <openerp> | ||
117 | 3 | <data noupdate="0"> | ||
118 | 4 | |||
119 | 5 | <!-- | ||
120 | 6 | Grupo | ||
121 | 7 | --> | ||
122 | 8 | <record id="group_nc_des_financiero_user" model="res.groups"> | ||
123 | 9 | <field name="name">NC para Descuento Financiero / User</field> | ||
124 | 10 | </record> | ||
125 | 11 | |||
126 | 12 | </data> | ||
127 | 13 | </openerp> | ||
128 | 0 | 14 | ||
129 | === added directory 'notas_de_credito/view' | |||
130 | === added file 'notas_de_credito/view/nota_credito_desc_financiero.xml' | |||
131 | --- notas_de_credito/view/nota_credito_desc_financiero.xml 1970-01-01 00:00:00 +0000 | |||
132 | +++ notas_de_credito/view/nota_credito_desc_financiero.xml 2013-04-26 02:38:26 +0000 | |||
133 | @@ -0,0 +1,62 @@ | |||
134 | 1 | <?xml version="1.0"?> | ||
135 | 2 | <openerp> | ||
136 | 3 | <data> | ||
137 | 4 | <record id="view_nc_product_tax_form" model="ir.ui.view"> | ||
138 | 5 | <field name="name">nota.credito.product_tax.form</field> | ||
139 | 6 | <field name="model">nota.credito.product_tax</field> | ||
140 | 7 | <field name="type">form</field> | ||
141 | 8 | <field name="arch" type="xml"> | ||
142 | 9 | <form string="Impuestos y productos asociados para la nota de credito"> | ||
143 | 10 | <group colspan="4" col="6"> | ||
144 | 11 | <group colspan="2" col="2"> | ||
145 | 12 | <field name="name"/> | ||
146 | 13 | <field name="tax_id" domain="[('type_tax_use','=','sale')]"/> | ||
147 | 14 | </group> | ||
148 | 15 | <group colspan="2" col="2"> | ||
149 | 16 | <field name="product_id" domain="[('type','=','service')]"/> | ||
150 | 17 | </group> | ||
151 | 18 | </group> | ||
152 | 19 | </form> | ||
153 | 20 | </field> | ||
154 | 21 | </record> | ||
155 | 22 | |||
156 | 23 | <record id="view_nc_product_tax_search" model="ir.ui.view"> | ||
157 | 24 | <field name="name">nota.credito.product_tax.search</field> | ||
158 | 25 | <field name="model">nota.credito.product_tax</field> | ||
159 | 26 | <field name="type">search</field> | ||
160 | 27 | <field name="arch" type="xml"> | ||
161 | 28 | <search string="Impuestos y productos"> | ||
162 | 29 | <field name="name"/> | ||
163 | 30 | <field name="tax_id"/> | ||
164 | 31 | <field name="product_id"/> | ||
165 | 32 | </search> | ||
166 | 33 | </field> | ||
167 | 34 | </record> | ||
168 | 35 | |||
169 | 36 | <record id="view_nc_product_tax_tree" model="ir.ui.view"> | ||
170 | 37 | <field name="name">nota.credito.product_tax.tree</field> | ||
171 | 38 | <field name="model">nota.credito.product_tax</field> | ||
172 | 39 | <field name="type">tree</field> | ||
173 | 40 | <field name="priority" eval="2"/> | ||
174 | 41 | <field name="arch" type="xml"> | ||
175 | 42 | <tree string="Impuestos y productos"> | ||
176 | 43 | <field name="name"/> | ||
177 | 44 | <field name="tax_id"/> | ||
178 | 45 | <field name="product_id"/> | ||
179 | 46 | </tree> | ||
180 | 47 | </field> | ||
181 | 48 | </record> | ||
182 | 49 | |||
183 | 50 | <record id="action_nc_product_tax_form" model="ir.actions.act_window"> | ||
184 | 51 | <field name="name">Impuestos y productos</field> | ||
185 | 52 | <field name="res_model">nota.credito.product_tax</field> | ||
186 | 53 | <field name="type">ir.actions.act_window</field> | ||
187 | 54 | <field name="view_type">form</field> | ||
188 | 55 | <field name="view_id" ref="view_nc_product_tax_tree"/> | ||
189 | 56 | <field name="search_view_id" ref="view_nc_product_tax_search"/> | ||
190 | 57 | <field name="help">Configurar los productos utilizados por cada impuesto en las notas de credito para descuentos financieros en ventas.</field> | ||
191 | 58 | </record> | ||
192 | 59 | <menuitem id="menu_action_nc_product_tax_desc_fin_form" name="Impuestos y productos para descuentos financieros" parent="account.menu_finance_configuration"/> | ||
193 | 60 | <menuitem action="action_nc_product_tax_form" id="menu_action_nc_product_tax_form" parent="menu_action_nc_product_tax_desc_fin_form"/> | ||
194 | 61 | </data> | ||
195 | 62 | </openerp> | ||
196 | 0 | 63 | ||
197 | === added directory 'notas_de_credito/wizard' | |||
198 | === added file 'notas_de_credito/wizard/__init__.py' | |||
199 | --- notas_de_credito/wizard/__init__.py 1970-01-01 00:00:00 +0000 | |||
200 | +++ notas_de_credito/wizard/__init__.py 2013-04-26 02:38:26 +0000 | |||
201 | @@ -0,0 +1,21 @@ | |||
202 | 1 | #!/usr/bin/python | ||
203 | 2 | # -*- encoding: utf-8 -*- | ||
204 | 3 | ###############Credits######################################################### | ||
205 | 4 | # Finance by: Industrias Diana, C.A. http://www.industriasdiana.gob.ve | ||
206 | 5 | ############################################################################### | ||
207 | 6 | # This program is free software: you can redistribute it and/or modify | ||
208 | 7 | # it under the terms of the GNU Affero General Public License as published by | ||
209 | 8 | # the Free Software Foundation, either version 3 of the License, or | ||
210 | 9 | # (at your option) any later version. | ||
211 | 10 | # | ||
212 | 11 | # This program is distributed in the hope that it will be useful, | ||
213 | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
214 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
215 | 14 | # GNU Affero General Public License for more details. | ||
216 | 15 | # | ||
217 | 16 | # You should have received a copy of the GNU Affero General Public License | ||
218 | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
219 | 18 | ############################################################################### | ||
220 | 19 | |||
221 | 20 | |||
222 | 21 | import nota_credito_1_x_100_wizard | ||
223 | 0 | 22 | ||
224 | === added file 'notas_de_credito/wizard/nota_credito_1_x_100_wizard.py' | |||
225 | --- notas_de_credito/wizard/nota_credito_1_x_100_wizard.py 1970-01-01 00:00:00 +0000 | |||
226 | +++ notas_de_credito/wizard/nota_credito_1_x_100_wizard.py 2013-04-26 02:38:26 +0000 | |||
227 | @@ -0,0 +1,235 @@ | |||
228 | 1 | # -*- encoding: utf-8 -*- | ||
229 | 2 | ############################################################################## | ||
230 | 3 | # Copyright (c) 2012 Industrias Diana C.A. | ||
231 | 4 | # All Rights Reserved. | ||
232 | 5 | # | ||
233 | 6 | # WARNING: This program as such is intended to be used by professional | ||
234 | 7 | # programmers who take the whole responsability of assessing all potential | ||
235 | 8 | # consequences resulting from its eventual inadequacies and bugs | ||
236 | 9 | # End users who are looking for a ready-to-use solution with commercial | ||
237 | 10 | # garantees and support are strongly adviced to contract a Free Software | ||
238 | 11 | # Service Company | ||
239 | 12 | # | ||
240 | 13 | # This program is Free Software; you can redistribute it and/or | ||
241 | 14 | # modify it under the terms of the GNU General Public License | ||
242 | 15 | # as published by the Free Software Foundation; either version 2 | ||
243 | 16 | # of the License, or (at your option) any later version. | ||
244 | 17 | # | ||
245 | 18 | # This program is distributed in the hope that it will be useful, | ||
246 | 19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
247 | 20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
248 | 21 | # GNU General Public License for more details. | ||
249 | 22 | # | ||
250 | 23 | # You should have received a copy of the GNU General Public License | ||
251 | 24 | # along with this program; if not, write to the Free Software | ||
252 | 25 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
253 | 26 | ############################################################################### | ||
254 | 27 | from datetime import datetime, timedelta | ||
255 | 28 | from dateutil.relativedelta import relativedelta | ||
256 | 29 | import time | ||
257 | 30 | |||
258 | 31 | from osv import osv | ||
259 | 32 | from osv import fields | ||
260 | 33 | import sys | ||
261 | 34 | from tools.translate import _ | ||
262 | 35 | import decimal_precision as dp | ||
263 | 36 | import netsvc | ||
264 | 37 | |||
265 | 38 | class nota_credito_1_x_100_wizard(osv.osv_memory): | ||
266 | 39 | """ | ||
267 | 40 | Forzar la confirmación del presupuesto para convertirse en un pedido de venta. | ||
268 | 41 | """ | ||
269 | 42 | _name = "nota.credito.1_x_100.wizard" | ||
270 | 43 | |||
271 | 44 | _description = "Nota de Credito por Descuento Financiero" | ||
272 | 45 | _columns = { | ||
273 | 46 | 'descuento': fields.integer('Descuento (%)', digits_compute= dp.get_precision('Account')), | ||
274 | 47 | } | ||
275 | 48 | |||
276 | 49 | _defaults = { | ||
277 | 50 | 'descuento': 1 | ||
278 | 51 | } | ||
279 | 52 | |||
280 | 53 | def _make_invoice(self, cr, uid, cabecera, lines, descuento, context=None): | ||
281 | 54 | journal_obj = self.pool.get('account.journal') | ||
282 | 55 | inv_obj = self.pool.get('account.invoice') | ||
283 | 56 | obj_invoice_line = self.pool.get('account.invoice.line') | ||
284 | 57 | if context is None: | ||
285 | 58 | context = {} | ||
286 | 59 | |||
287 | 60 | journal_id = cabecera.journal_id.sale_shop_id and cabecera.journal_id.sale_shop_id.refund_journal_id and cabecera.journal_id.sale_shop_id.refund_journal_id.id or False | ||
288 | 61 | if not journal_id: | ||
289 | 62 | raise osv.except_osv(_('Error !'), | ||
290 | 63 | _('There is no sales journal defined for this return: "%s"') % (cabecera.name)) | ||
291 | 64 | |||
292 | 65 | a = cabecera.partner_id.property_account_receivable.id | ||
293 | 66 | |||
294 | 67 | inv = { | ||
295 | 68 | 'name': 'RECTIFICA A ' + cabecera.number + ' DESCONTANDO EL ' + str(descuento) + '%', | ||
296 | 69 | 'origin': cabecera.origin, | ||
297 | 70 | 'type': 'out_refund', | ||
298 | 71 | 'reference': cabecera.number, | ||
299 | 72 | 'account_id': a, | ||
300 | 73 | 'partner_id': cabecera.partner_id.id, | ||
301 | 74 | 'journal_id': journal_id, | ||
302 | 75 | 'address_invoice_id': cabecera.address_invoice_id.id, | ||
303 | 76 | 'address_contact_id': cabecera.address_contact_id and cabecera.address_contact_id.id or False, | ||
304 | 77 | 'invoice_line': [(6, 0, lines)], | ||
305 | 78 | 'currency_id': cabecera.currency_id.id, | ||
306 | 79 | 'comment': 'Descuento financiero al ' + str(descuento) + '%', | ||
307 | 80 | 'fiscal_position': cabecera.partner_id.property_account_position.id, | ||
308 | 81 | 'date_invoice': time.strftime('%Y-%m-%d'), | ||
309 | 82 | 'company_id': cabecera.company_id.id, | ||
310 | 83 | 'user_id': cabecera.user_id and cabecera.user_id.id or False, | ||
311 | 84 | 'parent_id': cabecera.id, | ||
312 | 85 | 'address_shipping_id': cabecera.address_shipping_id.id, | ||
313 | 86 | } | ||
314 | 87 | |||
315 | 88 | inv_id = inv_obj.create(cr, uid, inv) | ||
316 | 89 | inv_obj.button_compute(cr, uid, [inv_id]) | ||
317 | 90 | |||
318 | 91 | return inv_id | ||
319 | 92 | |||
320 | 93 | def action_invoice_create(self, cr, uid, ids, res_ids, descuento, context=None): | ||
321 | 94 | if context is None: | ||
322 | 95 | context = {} | ||
323 | 96 | |||
324 | 97 | invoice_ids_refund = [] | ||
325 | 98 | |||
326 | 99 | invoice = self.pool.get('account.invoice') | ||
327 | 100 | obj_invoice_tax_ids = self.pool.get('account.invoice.tax') | ||
328 | 101 | if context is None: | ||
329 | 102 | context = {} | ||
330 | 103 | |||
331 | 104 | for out_inv in invoice.browse(cr, uid, res_ids, context=context): | ||
332 | 105 | invoices = {} | ||
333 | 106 | inv_line_id = False | ||
334 | 107 | create_ids = [] | ||
335 | 108 | #Buscar los impuesto de donde se van a sacar las lineas de la factura | ||
336 | 109 | ait_ids = obj_invoice_tax_ids.search(cr, uid, [('invoice_id','=',out_inv.id)],context=context) | ||
337 | 110 | #Por cada linea de impuesto crear una linea de la factura rectificativa | ||
338 | 111 | for line in obj_invoice_tax_ids.browse(cr, uid, ait_ids, context=context): | ||
339 | 112 | product_tax_id = self.pool.get('nota.credito.product_tax').search(cr, uid, [('tax_id','=',line.tax_id.id)], context=context) | ||
340 | 113 | |||
341 | 114 | if not product_tax_id: | ||
342 | 115 | raise osv.except_osv(_('Error !'), | ||
343 | 116 | _('There is no product for invoice refund defined ' \ | ||
344 | 117 | 'for this tax: "%s" ') % \ | ||
345 | 118 | (line.tax_id.name)) | ||
346 | 119 | |||
347 | 120 | product_tax = self.pool.get('nota.credito.product_tax').browse(cr, uid, product_tax_id[0], context=context) | ||
348 | 121 | |||
349 | 122 | #La cuenta de ingreso del producto | ||
350 | 123 | a = product_tax.product_id.product_tmpl_id.property_account_expense.id | ||
351 | 124 | if not a: | ||
352 | 125 | a = product_tax.product_id.categ_id.property_account_expense_categ.id | ||
353 | 126 | if not a: | ||
354 | 127 | a = self.get_product_category_account(cr,uid,product_tax.product_id.categ_id.id,"property_account_expense_categ",context=context) | ||
355 | 128 | if not a: | ||
356 | 129 | raise osv.except_osv(_('Error !'), | ||
357 | 130 | _('There is no income account defined ' \ | ||
358 | 131 | 'for this product: "%s" (id:%d)') % \ | ||
359 | 132 | (product_tax.product_id.name, product_tax.product_id.id,)) | ||
360 | 133 | |||
361 | 134 | inv_line_id = self.pool.get('account.invoice.line').create(cr, uid, { | ||
362 | 135 | 'name': self.pool.get('product.product').name_get(cr, uid, [product_tax.product_id.id])[0][1][:128], | ||
363 | 136 | 'origin': out_inv.origin, | ||
364 | 137 | 'account_id': a, | ||
365 | 138 | 'price_unit': line.base * descuento/100, | ||
366 | 139 | 'quantity': 1, | ||
367 | 140 | 'discount': 0.00, | ||
368 | 141 | 'uos_id': product_tax.product_id.uom_id.id, | ||
369 | 142 | 'product_id': product_tax.product_id.id, | ||
370 | 143 | 'invoice_line_tax_id': [(6, 0, [product_tax.tax_id.id])], | ||
371 | 144 | 'note': 'Descuento financiero al ' + str(descuento) + '%', | ||
372 | 145 | 'account_analytic_id': out_inv.journal_id.sale_shop_id and out_inv.journal_id.sale_shop_id.project_id and out_inv.journal_id.sale_shop_id.project_id.id or False, | ||
373 | 146 | 'accion_especifica_id': out_inv.journal_id.sale_shop_id and out_inv.journal_id.sale_shop_id.accion_especifica_id and out_inv.journal_id.sale_shop_id.accion_especifica_id.id or False, | ||
374 | 147 | 'partida_presupuesto': product_tax.product_id.partida_egreso and product_tax.product_id.partida_egreso.id or False, | ||
375 | 148 | }) | ||
376 | 149 | create_ids.append(inv_line_id) | ||
377 | 150 | |||
378 | 151 | #Se crea la factura rectificativa | ||
379 | 152 | if create_ids: | ||
380 | 153 | inv_id = self._make_invoice(cr, uid, out_inv, create_ids, descuento, context=context) | ||
381 | 154 | invoice_ids_refund.append(inv_id) | ||
382 | 155 | else: | ||
383 | 156 | inv_id = 0 | ||
384 | 157 | |||
385 | 158 | return invoice_ids_refund | ||
386 | 159 | |||
387 | 160 | def crear_nc(self, cr, uid, ids, context=None): | ||
388 | 161 | if context is None: | ||
389 | 162 | context = {} | ||
390 | 163 | |||
391 | 164 | aml_obj = self.pool.get('account.move.line') | ||
392 | 165 | wf_service = netsvc.LocalService("workflow") | ||
393 | 166 | |||
394 | 167 | act_obj = self.pool.get('ir.actions.act_window') | ||
395 | 168 | mod_obj = self.pool.get('ir.model.data') | ||
396 | 169 | model = context.get('active_model') | ||
397 | 170 | |||
398 | 171 | descuento_data_obj = self.read(cr, uid, ids, ['descuento']) | ||
399 | 172 | |||
400 | 173 | if not model or model != 'account.invoice': | ||
401 | 174 | return [] | ||
402 | 175 | |||
403 | 176 | if descuento_data_obj[0]['descuento'] < 1 or descuento_data_obj[0]['descuento'] > 100: | ||
404 | 177 | raise osv.except_osv(_('Mensaje !'), _('No se puede aplicar a una factura un descuento menor a 1% o mayor a 100% por este modulo!')) | ||
405 | 178 | |||
406 | 179 | res_ids = context and context.get('active_ids', []) | ||
407 | 180 | model_pool = self.pool.get(model) | ||
408 | 181 | browse_inv = model_pool.browse(cr, uid, res_ids, context=context) | ||
409 | 182 | #Proceso de validacion | ||
410 | 183 | validar_grupo_ok = True | ||
411 | 184 | number_inv = '' | ||
412 | 185 | for inv_disc in browse_inv: | ||
413 | 186 | if inv_disc.type != 'out_invoice' or inv_disc.state not in ('open') \ | ||
414 | 187 | or abs(inv_disc.residual - inv_disc.amount_total) > 0.01: | ||
415 | 188 | validar_grupo_ok = False | ||
416 | 189 | |||
417 | 190 | if not validar_grupo_ok: | ||
418 | 191 | number_inv = inv_disc.number or inv_disc.origin or inv_disc.state | ||
419 | 192 | break | ||
420 | 193 | |||
421 | 194 | #Se recomienda a futuro validar por fecha de vencimiento | ||
422 | 195 | |||
423 | 196 | #Si todas las facturas son de ventas | ||
424 | 197 | if validar_grupo_ok: | ||
425 | 198 | #crear las facturas | ||
426 | 199 | refund_invoice_ids = self.action_invoice_create(cr, uid, ids, res_ids, descuento_data_obj[0]['descuento'], context=context) | ||
427 | 200 | |||
428 | 201 | #procesar las facturas | ||
429 | 202 | for invoice in refund_invoice_ids: | ||
430 | 203 | wf_service.trg_validate(uid, 'account.invoice', invoice, 'invoice_open', cr) | ||
431 | 204 | |||
432 | 205 | """ Se concilian los asientos de la factura rectificativa y la factura padre """ | ||
433 | 206 | reconcil_ids = [] | ||
434 | 207 | for invoice in refund_invoice_ids: | ||
435 | 208 | reconcil_ids = [] | ||
436 | 209 | inv_refund = model_pool.browse(cr, uid, invoice, context=context) | ||
437 | 210 | for line_m_r in inv_refund.move_id.line_id: | ||
438 | 211 | if line_m_r.account_id == inv_refund.account_id: | ||
439 | 212 | reconcil_ids.append(line_m_r.id) | ||
440 | 213 | break | ||
441 | 214 | |||
442 | 215 | for line_m_i in inv_refund.parent_id.move_id.line_id: | ||
443 | 216 | if line_m_i.account_id == inv_refund.account_id: | ||
444 | 217 | reconcil_ids.append(line_m_i.id) | ||
445 | 218 | break | ||
446 | 219 | |||
447 | 220 | """ Se concilian los asientos de la factura """ | ||
448 | 221 | if reconcil_ids: | ||
449 | 222 | isok = aml_obj.reconcile_partial(cr, uid, reconcil_ids,'manual', context) | ||
450 | 223 | |||
451 | 224 | else: | ||
452 | 225 | raise osv.except_osv(_('Mensaje !'), _('Hay facturas seleccionadas que no se les puede aplicar nota de credito para descuento financieros. Por favor revise para empezar la factura %s!')%number_inv) | ||
453 | 226 | |||
454 | 227 | result = mod_obj.get_object_reference(cr, uid, 'account', 'action_invoice_tree3') | ||
455 | 228 | id = result and result[1] or False | ||
456 | 229 | result = act_obj.read(cr, uid, id, context=context) | ||
457 | 230 | invoice_domain = eval(result['domain']) | ||
458 | 231 | invoice_domain.append(('id', 'in', refund_invoice_ids)) | ||
459 | 232 | result['domain'] = invoice_domain | ||
460 | 233 | return result | ||
461 | 234 | |||
462 | 235 | nota_credito_1_x_100_wizard() | ||
463 | 0 | 236 | ||
464 | === added file 'notas_de_credito/wizard/nota_credito_1_x_100_wizard.xml' | |||
465 | --- notas_de_credito/wizard/nota_credito_1_x_100_wizard.xml 1970-01-01 00:00:00 +0000 | |||
466 | +++ notas_de_credito/wizard/nota_credito_1_x_100_wizard.xml 2013-04-26 02:38:26 +0000 | |||
467 | @@ -0,0 +1,32 @@ | |||
468 | 1 | <?xml version="1.0" encoding="utf-8"?> | ||
469 | 2 | <openerp> | ||
470 | 3 | <data> | ||
471 | 4 | <record id="view_nota_credito_1_x_100_wizard" model="ir.ui.view"> | ||
472 | 5 | <field name="name">Nota de Credito de 1 Porciento</field> | ||
473 | 6 | <field name="model">nota.credito.1_x_100.wizard</field> | ||
474 | 7 | <field name="type">form</field> | ||
475 | 8 | <field name="arch" type="xml"> | ||
476 | 9 | <form string="Crear Nota de Credito por descuento Financiero"> | ||
477 | 10 | <separator colspan="4" string="Crear Nota de Credito" /> | ||
478 | 11 | <group colspan="2" col="2"> | ||
479 | 12 | <field name="descuento"/> | ||
480 | 13 | </group> | ||
481 | 14 | <separator string="" colspan="4" /> | ||
482 | 15 | <button special="cancel" string="Cancelar" icon='gtk-cancel'/> | ||
483 | 16 | <button name="crear_nc" string="Crear" type="object" icon="terp-gtk-go-back-rtl"/> | ||
484 | 17 | </form> | ||
485 | 18 | </field> | ||
486 | 19 | </record> | ||
487 | 20 | |||
488 | 21 | |||
489 | 22 | <act_window name="Nota de Credito por Descuento Financiero" | ||
490 | 23 | res_model="nota.credito.1_x_100.wizard" | ||
491 | 24 | src_model="account.invoice" | ||
492 | 25 | key2="client_action_multi" | ||
493 | 26 | multi="True" | ||
494 | 27 | view_mode="form" | ||
495 | 28 | view_type="form" | ||
496 | 29 | target="new" | ||
497 | 30 | id="action_nota_credito_1_x_100"/> | ||
498 | 31 | </data> | ||
499 | 32 | </openerp> |