Merge lp:~inddiana/diana-addons/nota_credito_desc_financieros into lp:diana-addons/6.0

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
Reviewer Review Type Date Requested Status
Aristóbulo Meneses Pending
Review via email: mp+161058@code.launchpad.net

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
=== added directory 'notas_de_credito'
=== added file 'notas_de_credito/__init__.py'
--- notas_de_credito/__init__.py 1970-01-01 00:00:00 +0000
+++ notas_de_credito/__init__.py 2013-04-26 02:38:26 +0000
@@ -0,0 +1,4 @@
1# -*- coding: utf-8 -*-
2
3import model
4import wizard
05
=== added file 'notas_de_credito/__openerp__.py'
--- notas_de_credito/__openerp__.py 1970-01-01 00:00:00 +0000
+++ notas_de_credito/__openerp__.py 2013-04-26 02:38:26 +0000
@@ -0,0 +1,22 @@
1# -*- coding: utf-8 -*-
2
3{
4 "name" : "Registro nota de credito por descuentos financieros",
5 "version" : "1.0",
6 "author" : "Industrias Diana C.A.",
7 "category" : "Interfaces",
8 "website" : "http://www.industriasdiana.gob.ve",
9 "depends" : ["sisb_ventas",
10 'l10n_ve_presupuesto',
11 ],
12 "description": """Wizard para registrar nota de credito por descuentos financieros para facturas de ventas. Incluye la informacion para presupuesto.""",
13 "update_xml" : [
14 'security/nc_des_financiero_security.xml',
15 'security/ir.model.access.csv',
16 'view/nota_credito_desc_financiero.xml',
17 'wizard/nota_credito_1_x_100_wizard.xml',
18 ],
19 "active": False,
20 "installable": True,
21 'data' : [],
22}
023
=== added directory 'notas_de_credito/i18n'
=== added directory 'notas_de_credito/model'
=== added file 'notas_de_credito/model/__init__.py'
--- notas_de_credito/model/__init__.py 1970-01-01 00:00:00 +0000
+++ notas_de_credito/model/__init__.py 2013-04-26 02:38:26 +0000
@@ -0,0 +1,21 @@
1#!/usr/bin/python
2# -*- encoding: utf-8 -*-
3###############Credits#########################################################
4# Finance by: Industrias Diana, C.A. http://www.industriasdiana.gob.ve
5###############################################################################
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU Affero General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU Affero General Public License for more details.
15#
16# You should have received a copy of the GNU Affero General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18###############################################################################
19
20
21import product_tax
022
=== added file 'notas_de_credito/model/product_tax.py'
--- notas_de_credito/model/product_tax.py 1970-01-01 00:00:00 +0000
+++ notas_de_credito/model/product_tax.py 2013-04-26 02:38:26 +0000
@@ -0,0 +1,32 @@
1# -*- coding: utf-8 -*-
2"""
3Módulo utilizado para configurar los productos a escoger para asociar a las notas de credito del 1 porciento segun los impuestos
4"""
5
6import time
7import netsvc
8from osv import fields, osv
9from tools import config
10from tools.translate import _
11import decimal_precision as dp
12
13#----------------------------------------------------------
14# Productos tipo servicio y el impuesto asociado
15#----------------------------------------------------------
16
17class nota_credito_product_tax(osv.osv):
18 _name = "nota.credito.product_tax"
19 _description = "Productos de Notas de Credito"
20 _order = "name"
21
22 _columns = {
23 'name': fields.char('Nombre', size=64, select=True, required=True),
24 'tax_id': fields.many2one('account.tax', 'Impuesto', required=True),
25 'product_id': fields.many2one('product.product', 'Servicio de Descuento', required=True),
26 }
27 _sql_constraints = [
28 ('tax_product_uniq', 'unique (tax_id, product_id)', 'The combination of tax and product must be unique !'),
29 ]
30
31
32nota_credito_product_tax()
033
=== added directory 'notas_de_credito/security'
=== added file 'notas_de_credito/security/ir.model.access.csv'
--- notas_de_credito/security/ir.model.access.csv 1970-01-01 00:00:00 +0000
+++ notas_de_credito/security/ir.model.access.csv 2013-04-26 02:38:26 +0000
@@ -0,0 +1,2 @@
1"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
2"access_nc_des_financiero","nota_credito.product_tax","model_nota_credito_product_tax","group_nc_des_financiero_user",1,1,1,0
03
=== added file 'notas_de_credito/security/nc_des_financiero_security.xml'
--- notas_de_credito/security/nc_des_financiero_security.xml 1970-01-01 00:00:00 +0000
+++ notas_de_credito/security/nc_des_financiero_security.xml 2013-04-26 02:38:26 +0000
@@ -0,0 +1,13 @@
1<?xml version="1.0" encoding="utf-8"?>
2<openerp>
3 <data noupdate="0">
4
5<!--
6 Grupo
7-->
8 <record id="group_nc_des_financiero_user" model="res.groups">
9 <field name="name">NC para Descuento Financiero / User</field>
10 </record>
11
12 </data>
13</openerp>
014
=== added directory 'notas_de_credito/view'
=== added file 'notas_de_credito/view/nota_credito_desc_financiero.xml'
--- notas_de_credito/view/nota_credito_desc_financiero.xml 1970-01-01 00:00:00 +0000
+++ notas_de_credito/view/nota_credito_desc_financiero.xml 2013-04-26 02:38:26 +0000
@@ -0,0 +1,62 @@
1<?xml version="1.0"?>
2<openerp>
3 <data>
4 <record id="view_nc_product_tax_form" model="ir.ui.view">
5 <field name="name">nota.credito.product_tax.form</field>
6 <field name="model">nota.credito.product_tax</field>
7 <field name="type">form</field>
8 <field name="arch" type="xml">
9 <form string="Impuestos y productos asociados para la nota de credito">
10 <group colspan="4" col="6">
11 <group colspan="2" col="2">
12 <field name="name"/>
13 <field name="tax_id" domain="[('type_tax_use','=','sale')]"/>
14 </group>
15 <group colspan="2" col="2">
16 <field name="product_id" domain="[('type','=','service')]"/>
17 </group>
18 </group>
19 </form>
20 </field>
21 </record>
22
23 <record id="view_nc_product_tax_search" model="ir.ui.view">
24 <field name="name">nota.credito.product_tax.search</field>
25 <field name="model">nota.credito.product_tax</field>
26 <field name="type">search</field>
27 <field name="arch" type="xml">
28 <search string="Impuestos y productos">
29 <field name="name"/>
30 <field name="tax_id"/>
31 <field name="product_id"/>
32 </search>
33 </field>
34 </record>
35
36 <record id="view_nc_product_tax_tree" model="ir.ui.view">
37 <field name="name">nota.credito.product_tax.tree</field>
38 <field name="model">nota.credito.product_tax</field>
39 <field name="type">tree</field>
40 <field name="priority" eval="2"/>
41 <field name="arch" type="xml">
42 <tree string="Impuestos y productos">
43 <field name="name"/>
44 <field name="tax_id"/>
45 <field name="product_id"/>
46 </tree>
47 </field>
48 </record>
49
50 <record id="action_nc_product_tax_form" model="ir.actions.act_window">
51 <field name="name">Impuestos y productos</field>
52 <field name="res_model">nota.credito.product_tax</field>
53 <field name="type">ir.actions.act_window</field>
54 <field name="view_type">form</field>
55 <field name="view_id" ref="view_nc_product_tax_tree"/>
56 <field name="search_view_id" ref="view_nc_product_tax_search"/>
57 <field name="help">Configurar los productos utilizados por cada impuesto en las notas de credito para descuentos financieros en ventas.</field>
58 </record>
59 <menuitem id="menu_action_nc_product_tax_desc_fin_form" name="Impuestos y productos para descuentos financieros" parent="account.menu_finance_configuration"/>
60 <menuitem action="action_nc_product_tax_form" id="menu_action_nc_product_tax_form" parent="menu_action_nc_product_tax_desc_fin_form"/>
61 </data>
62</openerp>
063
=== added directory 'notas_de_credito/wizard'
=== added file 'notas_de_credito/wizard/__init__.py'
--- notas_de_credito/wizard/__init__.py 1970-01-01 00:00:00 +0000
+++ notas_de_credito/wizard/__init__.py 2013-04-26 02:38:26 +0000
@@ -0,0 +1,21 @@
1#!/usr/bin/python
2# -*- encoding: utf-8 -*-
3###############Credits#########################################################
4# Finance by: Industrias Diana, C.A. http://www.industriasdiana.gob.ve
5###############################################################################
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU Affero General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU Affero General Public License for more details.
15#
16# You should have received a copy of the GNU Affero General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18###############################################################################
19
20
21import nota_credito_1_x_100_wizard
022
=== added file 'notas_de_credito/wizard/nota_credito_1_x_100_wizard.py'
--- notas_de_credito/wizard/nota_credito_1_x_100_wizard.py 1970-01-01 00:00:00 +0000
+++ notas_de_credito/wizard/nota_credito_1_x_100_wizard.py 2013-04-26 02:38:26 +0000
@@ -0,0 +1,235 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3# Copyright (c) 2012 Industrias Diana C.A.
4# All Rights Reserved.
5#
6# WARNING: This program as such is intended to be used by professional
7# programmers who take the whole responsability of assessing all potential
8# consequences resulting from its eventual inadequacies and bugs
9# End users who are looking for a ready-to-use solution with commercial
10# garantees and support are strongly adviced to contract a Free Software
11# Service Company
12#
13# This program is Free Software; you can redistribute it and/or
14# modify it under the terms of the GNU General Public License
15# as published by the Free Software Foundation; either version 2
16# of the License, or (at your option) any later version.
17#
18# This program is distributed in the hope that it will be useful,
19# but WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21# GNU General Public License for more details.
22#
23# You should have received a copy of the GNU General Public License
24# along with this program; if not, write to the Free Software
25# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26###############################################################################
27from datetime import datetime, timedelta
28from dateutil.relativedelta import relativedelta
29import time
30
31from osv import osv
32from osv import fields
33import sys
34from tools.translate import _
35import decimal_precision as dp
36import netsvc
37
38class nota_credito_1_x_100_wizard(osv.osv_memory):
39 """
40 Forzar la confirmación del presupuesto para convertirse en un pedido de venta.
41 """
42 _name = "nota.credito.1_x_100.wizard"
43
44 _description = "Nota de Credito por Descuento Financiero"
45 _columns = {
46 'descuento': fields.integer('Descuento (%)', digits_compute= dp.get_precision('Account')),
47 }
48
49 _defaults = {
50 'descuento': 1
51 }
52
53 def _make_invoice(self, cr, uid, cabecera, lines, descuento, context=None):
54 journal_obj = self.pool.get('account.journal')
55 inv_obj = self.pool.get('account.invoice')
56 obj_invoice_line = self.pool.get('account.invoice.line')
57 if context is None:
58 context = {}
59
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
61 if not journal_id:
62 raise osv.except_osv(_('Error !'),
63 _('There is no sales journal defined for this return: "%s"') % (cabecera.name))
64
65 a = cabecera.partner_id.property_account_receivable.id
66
67 inv = {
68 'name': 'RECTIFICA A ' + cabecera.number + ' DESCONTANDO EL ' + str(descuento) + '%',
69 'origin': cabecera.origin,
70 'type': 'out_refund',
71 'reference': cabecera.number,
72 'account_id': a,
73 'partner_id': cabecera.partner_id.id,
74 'journal_id': journal_id,
75 'address_invoice_id': cabecera.address_invoice_id.id,
76 'address_contact_id': cabecera.address_contact_id and cabecera.address_contact_id.id or False,
77 'invoice_line': [(6, 0, lines)],
78 'currency_id': cabecera.currency_id.id,
79 'comment': 'Descuento financiero al ' + str(descuento) + '%',
80 'fiscal_position': cabecera.partner_id.property_account_position.id,
81 'date_invoice': time.strftime('%Y-%m-%d'),
82 'company_id': cabecera.company_id.id,
83 'user_id': cabecera.user_id and cabecera.user_id.id or False,
84 'parent_id': cabecera.id,
85 'address_shipping_id': cabecera.address_shipping_id.id,
86 }
87
88 inv_id = inv_obj.create(cr, uid, inv)
89 inv_obj.button_compute(cr, uid, [inv_id])
90
91 return inv_id
92
93 def action_invoice_create(self, cr, uid, ids, res_ids, descuento, context=None):
94 if context is None:
95 context = {}
96
97 invoice_ids_refund = []
98
99 invoice = self.pool.get('account.invoice')
100 obj_invoice_tax_ids = self.pool.get('account.invoice.tax')
101 if context is None:
102 context = {}
103
104 for out_inv in invoice.browse(cr, uid, res_ids, context=context):
105 invoices = {}
106 inv_line_id = False
107 create_ids = []
108 #Buscar los impuesto de donde se van a sacar las lineas de la factura
109 ait_ids = obj_invoice_tax_ids.search(cr, uid, [('invoice_id','=',out_inv.id)],context=context)
110 #Por cada linea de impuesto crear una linea de la factura rectificativa
111 for line in obj_invoice_tax_ids.browse(cr, uid, ait_ids, context=context):
112 product_tax_id = self.pool.get('nota.credito.product_tax').search(cr, uid, [('tax_id','=',line.tax_id.id)], context=context)
113
114 if not product_tax_id:
115 raise osv.except_osv(_('Error !'),
116 _('There is no product for invoice refund defined ' \
117 'for this tax: "%s" ') % \
118 (line.tax_id.name))
119
120 product_tax = self.pool.get('nota.credito.product_tax').browse(cr, uid, product_tax_id[0], context=context)
121
122 #La cuenta de ingreso del producto
123 a = product_tax.product_id.product_tmpl_id.property_account_expense.id
124 if not a:
125 a = product_tax.product_id.categ_id.property_account_expense_categ.id
126 if not a:
127 a = self.get_product_category_account(cr,uid,product_tax.product_id.categ_id.id,"property_account_expense_categ",context=context)
128 if not a:
129 raise osv.except_osv(_('Error !'),
130 _('There is no income account defined ' \
131 'for this product: "%s" (id:%d)') % \
132 (product_tax.product_id.name, product_tax.product_id.id,))
133
134 inv_line_id = self.pool.get('account.invoice.line').create(cr, uid, {
135 'name': self.pool.get('product.product').name_get(cr, uid, [product_tax.product_id.id])[0][1][:128],
136 'origin': out_inv.origin,
137 'account_id': a,
138 'price_unit': line.base * descuento/100,
139 'quantity': 1,
140 'discount': 0.00,
141 'uos_id': product_tax.product_id.uom_id.id,
142 'product_id': product_tax.product_id.id,
143 'invoice_line_tax_id': [(6, 0, [product_tax.tax_id.id])],
144 'note': 'Descuento financiero al ' + str(descuento) + '%',
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,
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,
147 'partida_presupuesto': product_tax.product_id.partida_egreso and product_tax.product_id.partida_egreso.id or False,
148 })
149 create_ids.append(inv_line_id)
150
151 #Se crea la factura rectificativa
152 if create_ids:
153 inv_id = self._make_invoice(cr, uid, out_inv, create_ids, descuento, context=context)
154 invoice_ids_refund.append(inv_id)
155 else:
156 inv_id = 0
157
158 return invoice_ids_refund
159
160 def crear_nc(self, cr, uid, ids, context=None):
161 if context is None:
162 context = {}
163
164 aml_obj = self.pool.get('account.move.line')
165 wf_service = netsvc.LocalService("workflow")
166
167 act_obj = self.pool.get('ir.actions.act_window')
168 mod_obj = self.pool.get('ir.model.data')
169 model = context.get('active_model')
170
171 descuento_data_obj = self.read(cr, uid, ids, ['descuento'])
172
173 if not model or model != 'account.invoice':
174 return []
175
176 if descuento_data_obj[0]['descuento'] < 1 or descuento_data_obj[0]['descuento'] > 100:
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!'))
178
179 res_ids = context and context.get('active_ids', [])
180 model_pool = self.pool.get(model)
181 browse_inv = model_pool.browse(cr, uid, res_ids, context=context)
182 #Proceso de validacion
183 validar_grupo_ok = True
184 number_inv = ''
185 for inv_disc in browse_inv:
186 if inv_disc.type != 'out_invoice' or inv_disc.state not in ('open') \
187 or abs(inv_disc.residual - inv_disc.amount_total) > 0.01:
188 validar_grupo_ok = False
189
190 if not validar_grupo_ok:
191 number_inv = inv_disc.number or inv_disc.origin or inv_disc.state
192 break
193
194 #Se recomienda a futuro validar por fecha de vencimiento
195
196 #Si todas las facturas son de ventas
197 if validar_grupo_ok:
198 #crear las facturas
199 refund_invoice_ids = self.action_invoice_create(cr, uid, ids, res_ids, descuento_data_obj[0]['descuento'], context=context)
200
201 #procesar las facturas
202 for invoice in refund_invoice_ids:
203 wf_service.trg_validate(uid, 'account.invoice', invoice, 'invoice_open', cr)
204
205 """ Se concilian los asientos de la factura rectificativa y la factura padre """
206 reconcil_ids = []
207 for invoice in refund_invoice_ids:
208 reconcil_ids = []
209 inv_refund = model_pool.browse(cr, uid, invoice, context=context)
210 for line_m_r in inv_refund.move_id.line_id:
211 if line_m_r.account_id == inv_refund.account_id:
212 reconcil_ids.append(line_m_r.id)
213 break
214
215 for line_m_i in inv_refund.parent_id.move_id.line_id:
216 if line_m_i.account_id == inv_refund.account_id:
217 reconcil_ids.append(line_m_i.id)
218 break
219
220 """ Se concilian los asientos de la factura """
221 if reconcil_ids:
222 isok = aml_obj.reconcile_partial(cr, uid, reconcil_ids,'manual', context)
223
224 else:
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)
226
227 result = mod_obj.get_object_reference(cr, uid, 'account', 'action_invoice_tree3')
228 id = result and result[1] or False
229 result = act_obj.read(cr, uid, id, context=context)
230 invoice_domain = eval(result['domain'])
231 invoice_domain.append(('id', 'in', refund_invoice_ids))
232 result['domain'] = invoice_domain
233 return result
234
235nota_credito_1_x_100_wizard()
0236
=== added file 'notas_de_credito/wizard/nota_credito_1_x_100_wizard.xml'
--- notas_de_credito/wizard/nota_credito_1_x_100_wizard.xml 1970-01-01 00:00:00 +0000
+++ notas_de_credito/wizard/nota_credito_1_x_100_wizard.xml 2013-04-26 02:38:26 +0000
@@ -0,0 +1,32 @@
1<?xml version="1.0" encoding="utf-8"?>
2<openerp>
3 <data>
4 <record id="view_nota_credito_1_x_100_wizard" model="ir.ui.view">
5 <field name="name">Nota de Credito de 1 Porciento</field>
6 <field name="model">nota.credito.1_x_100.wizard</field>
7 <field name="type">form</field>
8 <field name="arch" type="xml">
9 <form string="Crear Nota de Credito por descuento Financiero">
10 <separator colspan="4" string="Crear Nota de Credito" />
11 <group colspan="2" col="2">
12 <field name="descuento"/>
13 </group>
14 <separator string="" colspan="4" />
15 <button special="cancel" string="Cancelar" icon='gtk-cancel'/>
16 <button name="crear_nc" string="Crear" type="object" icon="terp-gtk-go-back-rtl"/>
17 </form>
18 </field>
19 </record>
20
21
22 <act_window name="Nota de Credito por Descuento Financiero"
23 res_model="nota.credito.1_x_100.wizard"
24 src_model="account.invoice"
25 key2="client_action_multi"
26 multi="True"
27 view_mode="form"
28 view_type="form"
29 target="new"
30 id="action_nota_credito_1_x_100"/>
31 </data>
32</openerp>

Subscribers

People subscribed via source and target branches