Merge lp:~vauxoo/openerp-venezuela-localization/gaby-merge-debit-credit-fiscal-requirements into lp:~openerp-venezuela/openerp-venezuela-localization/6.0-trunk

Proposed by Gabriela Quilarque
Status: Merged
Merged at revision: 472
Proposed branch: lp:~vauxoo/openerp-venezuela-localization/gaby-merge-debit-credit-fiscal-requirements
Merge into: lp:~openerp-venezuela/openerp-venezuela-localization/6.0-trunk
Diff against target: 814 lines (+730/-0) (has conflicts)
10 files modified
l10n_ve_fiscal_requirements/__init__.py (+1/-0)
l10n_ve_fiscal_requirements/__openerp__.py (+9/-0)
l10n_ve_fiscal_requirements/account_invoice_view.xml (+92/-0)
l10n_ve_fiscal_requirements/i18n/es_VE.po (+112/-0)
l10n_ve_fiscal_requirements/invoice.py (+2/-0)
l10n_ve_fiscal_requirements/security/ir.model.access.csv (+1/-0)
l10n_ve_fiscal_requirements/wizard/__init__.py (+2/-0)
l10n_ve_fiscal_requirements/wizard/account_invoice_debit.py (+233/-0)
l10n_ve_fiscal_requirements/wizard/account_invoice_debit_view.xml (+43/-0)
l10n_ve_fiscal_requirements/wizard/account_invoice_refund.py (+235/-0)
Text conflict in l10n_ve_fiscal_requirements/__openerp__.py
To merge this branch: bzr merge lp:~vauxoo/openerp-venezuela-localization/gaby-merge-debit-credit-fiscal-requirements
Reviewer Review Type Date Requested Status
Nhomar - Vauxoo Pending
Gabriela Quilarque Pending
Review via email: mp+81218@code.launchpad.net

Description of the change

Merge debit_credit_note to l10n_ve_fiscal_requirements:

Improvements:
-Translations.
-Security.
-Update invoice view.
-Update description in __openerp__.py.
-Merge modules.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'l10n_ve_fiscal_requirements/__init__.py'
--- l10n_ve_fiscal_requirements/__init__.py 2011-10-25 20:33:16 +0000
+++ l10n_ve_fiscal_requirements/__init__.py 2011-11-03 23:12:26 +0000
@@ -29,4 +29,5 @@
29import seniat_url29import seniat_url
30import l10n_ut30import l10n_ut
31import wizard31import wizard
32
32# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:33# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
3334
=== modified file 'l10n_ve_fiscal_requirements/__openerp__.py'
--- l10n_ve_fiscal_requirements/__openerp__.py 2011-11-03 19:22:42 +0000
+++ l10n_ve_fiscal_requirements/__openerp__.py 2011-11-03 23:12:26 +0000
@@ -38,9 +38,16 @@
38Automatically on install wizard.38Automatically on install wizard.
39 - Damaged "Legal free forms" declaration.39 - Damaged "Legal free forms" declaration.
40 - Tax Units configuration.40 - Tax Units configuration.
41<<<<<<< TREE
41 - When a partner is updated by using the SENIAT Update Button, its name changes to42 - When a partner is updated by using the SENIAT Update Button, its name changes to
42 readonly to avoid manual changes.43 readonly to avoid manual changes.
43 ---------------------------------------------------------------------------44 ---------------------------------------------------------------------------
45=======
46 - Added field Parent in the invoice of customers and suppliers, for link the invoice
47 that generated debit or credit note.
48 --Added wizard for generate debit note from invoice and done accounting entry.
49 -------------------------------------------------------------------------------------------
50>>>>>>> MERGE-SOURCE
44 For damaged invoices (Free form formats), you must go to the company and, under the configuration section,51 For damaged invoices (Free form formats), you must go to the company and, under the configuration section,
45 create the corresponding journal and account.52 create the corresponding journal and account.
46 TODO : Include this on wizard configuration.53 TODO : Include this on wizard configuration.
@@ -69,6 +76,8 @@
69 'wizard/wizard_nro_ctrl_view.xml',76 'wizard/wizard_nro_ctrl_view.xml',
70 'wizard/wizard_url_seniat_view.xml',77 'wizard/wizard_url_seniat_view.xml',
71 'wizard/update_info_partner.xml',78 'wizard/update_info_partner.xml',
79 'wizard/account_invoice_debit_view.xml',
80 'account_invoice_view.xml',
72 ],81 ],
73 'demo_xml': [82 'demo_xml': [
74 'demo/demo_partners.xml',83 'demo/demo_partners.xml',
7584
=== added file 'l10n_ve_fiscal_requirements/account_invoice_view.xml'
--- l10n_ve_fiscal_requirements/account_invoice_view.xml 1970-01-01 00:00:00 +0000
+++ l10n_ve_fiscal_requirements/account_invoice_view.xml 2011-11-03 23:12:26 +0000
@@ -0,0 +1,92 @@
1<?xml version="1.0" encoding="utf-8"?>
2<openerp>
3 <data>
4
5
6
7 <!--
8 =====================================================
9 Invoices Extension
10 =====================================================
11 -->
12
13 <record id="account_inv_ext_view_form_crdr" model="ir.ui.view">
14 <field name="name">invoice_extended.form.crdr</field>
15 <field name="model">account.invoice</field>
16 <field name="type">form</field>
17 <field name="inherit_id" ref="account.invoice_form"/>
18 <field name="arch" type="xml">
19 <notebook>
20 <page string="Debit-Credit Notes" position="inside">
21 <field name="child_ids" nolabel="1" widget="many2many" domain="[('partner_id','=',partner_id),('id', '!=', active_id),('type','in',['out_invoice', 'out_refund'])]"/>
22 </page>
23 </notebook>
24 </field>
25 </record>
26
27
28
29 <record id="account_inv_ext_view_supp_form_crdr" model="ir.ui.view">
30 <field name="name">invoice_extended.supplier.form.crdr</field>
31 <field name="model">account.invoice</field>
32 <field name="type">form</field>
33 <field name="inherit_id" ref="account.invoice_supplier_form"/>
34 <field name="arch" type="xml">
35 <notebook>
36 <page string="Debit-Credit Notes" position="inside">
37 <field name="child_ids" nolabel="1" widget="many2many" domain="[('partner_id','=',partner_id),('id', '!=', active_id),('type','in',['in_invoice', 'in_refund'])]"/>
38 </page>
39 </notebook>
40 </field>
41 </record>
42
43
44 <record id="account_inv_ext_view_tree_crdr" model="ir.ui.view">
45 <field name="name">invoice_extended.tree.crdr</field>
46 <field name="model">account.invoice</field>
47 <field name="type">tree</field>
48 <field name="inherit_id" ref="account.invoice_tree"/>
49 <field name="arch" type="xml">
50 <xpath expr="/tree/field[@name='origin']" position="after">
51 <field name="parent_id"/>
52 </xpath>
53 </field>
54 </record>
55 <record id="account_inv_ext_form_crdrc" model="ir.ui.view">
56 <field name="name">invoice_ext.form.crdrc</field>
57 <field name="model">account.invoice</field>
58 <field name="type">tree</field>
59 <field name="inherit_id" ref="account.invoice_form"/>
60 <field name="arch" type="xml">
61 <xpath expr="/form/group/group" position="after">
62 <newline/>
63 <field name="parent_id" attrs="{'required':[('type','=','out_refund')]}" domain="[('partner_id','=',partner_id),('id', '!=', active_id),('type','in',['out_invoice', 'out_refund'])]"/>
64 </xpath>
65 <xpath expr="//button[@string='Refund']" position="after">
66 <button name="%(action_account_invoice_debit)d" type='action' string='Debit Note' states='open,paid' icon="gtk-execute" attrs="{'invisible':[('type','in',['in_refund', 'out_refund'])]}"/>
67 </xpath>
68 </field>
69 </record>
70 <record id="account_inv_ext_form_crdrs" model="ir.ui.view">
71 <field name="name">invoice_ext.form.crdrs</field>
72 <field name="model">account.invoice</field>
73 <field name="type">tree</field>
74 <field name="inherit_id" ref="account.invoice_supplier_form"/>
75 <field name="arch" type="xml">
76 <xpath expr="/form/group/group" position="after">
77 <newline/>
78 <field name="parent_id" attrs="{'required':[('type','=','in_refund')]}" domain="[('partner_id','=',partner_id),('id', '!=', active_id),('type','in',['in_invoice', 'in_refund'])]"/>
79 </xpath>
80 <xpath expr="//button[@string='Refund']" position="after">
81 <button name="%(action_account_invoice_debit)d" type='action' string='Debit Note' states='open,paid' icon="gtk-execute" attrs="{'invisible':[('type','in',['in_refund', 'out_refund'])]}"/>
82 </xpath>
83 </field>
84 </record>
85
86
87
88
89
90
91 </data>
92</openerp>
093
=== modified file 'l10n_ve_fiscal_requirements/i18n/es_VE.po'
--- l10n_ve_fiscal_requirements/i18n/es_VE.po 2011-11-02 13:13:38 +0000
+++ l10n_ve_fiscal_requirements/i18n/es_VE.po 2011-11-03 23:12:26 +0000
@@ -390,3 +390,115 @@
390msgid "Date on which goes into effect the new Unit Tax Unit"390msgid "Date on which goes into effect the new Unit Tax Unit"
391msgstr "Fecha en la cual entra en vigencia la nueva Unidad Tributaria"391msgstr "Fecha en la cual entra en vigencia la nueva Unidad Tributaria"
392392
393#. module: l10n_ve_fiscal_requirements
394#: code:addons/l10n_ve_fiscal_requirements/wizard/account_invoice_debit.py:125
395#, python-format
396msgid "Can not create a debit note from invoice which is already reconciled, invoice should be unreconciled first. You can only Refund or Debit this invoice"
397msgstr "Can not create a debit note from invoice which is already reconciled, invoice should be unreconciled first. You can only Refund or Debit this invoice"
398
399#. module: l10n_ve_fiscal_requirements
400#: view:account.invoice:0
401#: view:account.invoice.debit:0
402#: model:ir.actions.act_window,name:l10n_ve_fiscal_requirements.action_account_invoice_debit
403msgid "Debit Note"
404msgstr "Nota de Debito"
405
406#. module: l10n_ve_fiscal_requirements
407#: field:account.invoice,child_ids:0
408msgid "Debit and Credit Notes"
409msgstr "Notas de Débito/Crédito"
410
411#. module: l10n_ve_fiscal_requirements
412#: view:account.invoice.debit:0
413msgid "Debit Invoice: Creates the debit note invoice, ready for editing."
414msgstr "Nota de Débito: Crea la nota de dédito lista para ser editada."
415
416#. module: l10n_ve_fiscal_requirements
417#: view:account.invoice.debit:0
418msgid "Debit Note Options"
419msgstr "Opciones Nota de Débito"
420
421#. module: l10n_ve_fiscal_requirements
422#: field:account.invoice.debit,comment:0
423msgid "Comment"
424msgstr "Comentario"
425
426#. module: l10n_ve_fiscal_requirements
427#: code:addons/l10n_ve_fiscal_requirements/wizard/account_invoice_refund.py:109
428#, python-format
429msgid "Can not %s invoice which is already reconciled, invoice should be unreconciled first. You can only Refund this invoice"
430msgstr "Imposible generar una nota de crédito cuando la factura %s ya esta conciliada, primero debes realizar la desconciliación."
431
432#. module: l10n_ve_fiscal_requirements
433#: model:ir.model,name:l10n_ve_fiscal_requirements.model_account_invoice_debit
434msgid "Invoice Debit Note"
435msgstr "Nota de Débito"
436
437#. module: l10n_ve_fiscal_requirements
438#: code:addons/l10n_ve_fiscal_requirements/wizard/account_invoice_debit.py:123
439#, python-format
440msgid "Can not create a debit note from draft/proforma/cancel invoice."
441msgstr "Imposible crear nota de débito desde draft/proforma/cancel invoice."
442
443#. module: l10n_ve_fiscal_requirements
444#: help:account.invoice.debit,journal_id:0
445msgid "You can select here the journal to use for the refund invoice that will be created. If you leave that field empty, it will use the same journal as the current invoice."
446msgstr "Puedes seleccionar un diario para la nota de débito que será creada. Si dejas este campo vacio, se usará el diario de la factura actual."
447
448#. module: l10n_ve_fiscal_requirements
449#: code:addons/l10n_ve_fiscal_requirements/wizard/account_invoice_debit.py:168
450#: code:addons/l10n_ve_fiscal_requirements/wizard/account_invoice_refund.py:148
451#, python-format
452msgid "Data Insufficient !"
453msgstr "Datos Insuficientes !"
454
455#. module: l10n_ve_fiscal_requirements
456#: field:account.invoice.debit,description:0
457msgid "Description"
458msgstr "Descripción"
459
460#. module: l10n_ve_fiscal_requirements
461#: help:account.invoice.debit,date:0
462msgid "This date will be used as the invoice date for Refund Invoice and Period will be chosen accordingly!"
463msgstr "Puedes definir la fecha que tendrá la Nota de Débito."
464
465#. module: l10n_ve_fiscal_requirements
466#: model:ir.model,name:l10n_ve_fiscal_requirements.model_account_invoice_refund
467msgid "Invoice Refund"
468msgstr "Nota de Crédito"
469
470#. module: l10n_ve_fiscal_requirements
471#: view:account.invoice:0
472msgid "Debit-Credit Notes"
473msgstr "Notas de Débito/Crédito"
474
475#. module: l10n_ve_fiscal_requirements
476#: help:account.invoice,parent_id:0
477msgid "When this field has information, this invoice is a credit note or debit note. This field is used to reference to the invoice that originated this credit note or debit note."
478msgstr "Cuando este campo contiene información, estamos en presencia de una Nota de Crédito o Débito. Es usado para referenciar a la factura desde donde se originó la Nota de Crédito o Débito."
479
480#. module: l10n_ve_fiscal_requirements
481#: code:addons/l10n_ve_fiscal_requirements/wizard/account_invoice_debit.py:127
482#, python-format
483msgid "Can not make a debit note on a refund invoice."
484msgstr "No puedes crear una nota de débito o credito."
485
486#. module: l10n_ve_fiscal_requirements
487#: field:account.invoice,parent_id:0
488msgid "Parent Invoice"
489msgstr "Factura Origen"
490
491#. module: l10n_ve_fiscal_requirements
492#: field:account.invoice.debit,date:0
493msgid "Operation date"
494msgstr "Fecha operación"
495
496#. module: l10n_ve_fiscal_requirements
497#: field:account.invoice.debit,journal_id:0
498msgid "Refund Journal"
499msgstr "Diario Reembolso"
500
501#. module: l10n_ve_fiscal_requirements
502#: field:account.invoice.debit,period:0
503msgid "Force period"
504msgstr "Periodo"
393505
=== modified file 'l10n_ve_fiscal_requirements/invoice.py'
--- l10n_ve_fiscal_requirements/invoice.py 2011-10-25 20:33:16 +0000
+++ l10n_ve_fiscal_requirements/invoice.py 2011-11-03 23:12:26 +0000
@@ -31,6 +31,8 @@
31 _columns = {31 _columns = {
32 'nro_ctrl': fields.char('Control Number', size=32, readonly=True, states={'draft':[('readonly',False)]}, help="Code used for intern invoice control"),32 'nro_ctrl': fields.char('Control Number', size=32, readonly=True, states={'draft':[('readonly',False)]}, help="Code used for intern invoice control"),
33 'sin_cred': fields.boolean('Tax-exempt?', readonly=False, help="Set it true if the invoice is V.A.T. exempt"),33 'sin_cred': fields.boolean('Tax-exempt?', readonly=False, help="Set it true if the invoice is V.A.T. exempt"),
34 'parent_id':fields.many2one('account.invoice', 'Parent Invoice', readonly=True, states={'draft':[('readonly',False)]}, help='When this field has information, this invoice is a credit note or debit note. This field is used to reference to the invoice that originated this credit note or debit note.'),
35 'child_ids':fields.one2many('account.invoice', 'parent_id', 'Debit and Credit Notes', readonly=True, states={'draft':[('readonly',False)]}),
34 }36 }
35account_invoice()37account_invoice()
3638
3739
=== modified file 'l10n_ve_fiscal_requirements/security/ir.model.access.csv'
--- l10n_ve_fiscal_requirements/security/ir.model.access.csv 2011-10-29 15:51:25 +0000
+++ l10n_ve_fiscal_requirements/security/ir.model.access.csv 2011-11-03 23:12:26 +0000
@@ -4,3 +4,4 @@
4"access_account_seniat_url_3","seniat.url","model_seniat_url","account.group_account_manager",1,1,1,14"access_account_seniat_url_3","seniat.url","model_seniat_url","account.group_account_manager",1,1,1,1
5"access_account_seniat_url_4","seniat.url","model_seniat_url","base.group_erp_manager",1,1,1,15"access_account_seniat_url_4","seniat.url","model_seniat_url","base.group_erp_manager",1,1,1,1
6"access_account_seniat_url_5","seniat.url","model_seniat_url","base.group_partner_manager",1,0,0,06"access_account_seniat_url_5","seniat.url","model_seniat_url","base.group_partner_manager",1,0,0,0
7"access_account_invoice_debit_6","account.invoice.debit","model_account_invoice_debit","base.group_partner_manager",1,0,0,0
78
=== modified file 'l10n_ve_fiscal_requirements/wizard/__init__.py'
--- l10n_ve_fiscal_requirements/wizard/__init__.py 2011-10-25 20:33:16 +0000
+++ l10n_ve_fiscal_requirements/wizard/__init__.py 2011-11-03 23:12:26 +0000
@@ -27,3 +27,5 @@
27import wizard_invoice_nro_ctrl27import wizard_invoice_nro_ctrl
28import wizard_url_seniat28import wizard_url_seniat
29import update_info_partner29import update_info_partner
30import account_invoice_refund
31import account_invoice_debit
3032
=== added file 'l10n_ve_fiscal_requirements/wizard/account_invoice_debit.py'
--- l10n_ve_fiscal_requirements/wizard/account_invoice_debit.py 1970-01-01 00:00:00 +0000
+++ l10n_ve_fiscal_requirements/wizard/account_invoice_debit.py 2011-11-03 23:12:26 +0000
@@ -0,0 +1,233 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22import time
23
24from osv import fields, osv
25from tools.translate import _
26import netsvc
27
28class account_invoice_debit(osv.osv_memory):
29
30 """Debits Note from Invoice"""
31
32 _name = "account.invoice.debit"
33 _description = "Invoice Debit Note"
34 _columns = {
35 'date': fields.date('Operation date', help='This date will be used as the invoice date for Refund Invoice and Period will be chosen accordingly!'),
36 'period': fields.many2one('account.period', 'Force period'),
37 'journal_id': fields.many2one('account.journal', 'Refund Journal', help='You can select here the journal to use for the refund invoice that will be created. If you leave that field empty, it will use the same journal as the current invoice.'),
38 'description': fields.char('Description', size=128, required=True),
39 'comment': fields.text('Comment', required=True),
40 }
41
42 def _get_journal(self, cr, uid, context=None):
43 obj_journal = self.pool.get('account.journal')
44 if context is None:
45 context = {}
46 journal = obj_journal.search(cr, uid, [('type', '=', 'sale')])
47 if context.get('type', False):
48 if context['type'] in ('in_invoice', 'in_refund'):
49 journal = obj_journal.search(cr, uid, [('type', '=', 'purchase')])
50 return journal and journal[0] or False
51
52 _defaults = {
53 'date': lambda *a: time.strftime('%Y-%m-%d'),
54 'journal_id': _get_journal,
55 'filter_refund': 'modify',
56 }
57
58 def fields_view_get(self, cr, uid, view_id=None, view_type=False, context=None, toolbar=False, submenu=False):
59 journal_obj = self.pool.get('account.journal')
60 res = super(account_invoice_debit,self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
61 #Debit note only from customer o purchase invoice
62 #type = context.get('journal_type', 'sale_refund')
63 type = context.get('journal_type', 'sale')
64 if type in ('sale', 'sale_refund'):
65 type = 'sale'
66 else:
67 type = 'purchase'
68 for field in res['fields']:
69 if field == 'journal_id':
70 journal_select = journal_obj._name_search(cr, uid, '', [('type', '=', type)], context=context, limit=None, name_get_uid=1)
71 res['fields'][field]['selection'] = journal_select
72 return res
73
74 def _get_period(self, cr, uid, context={}):
75 """
76 Return default account period value
77 """
78 account_period_obj = self.pool.get('account.period')
79 ids = account_period_obj.find(cr, uid, context=context)
80 period_id = False
81 if ids:
82 period_id = ids[0]
83 return period_id
84
85 def _get_orig(self, cr, uid, inv, ref, context={}):
86 """
87 Return default origin value
88 """
89 nro_ref = ref
90 if inv.type == 'out_invoice':
91 nro_ref = inv.number
92 orig = 'FACT:' +(nro_ref or '') + '- DE FECHA:' + (inv.date_invoice or '') + (' TOTAL:' + str(inv.amount_total) or '')
93 return orig
94
95 def compute_debit(self, cr, uid, ids, context=None):
96 """
97 @param cr: the current row, from the database cursor,
98 @param uid: the current user’s ID for security checks,
99 @param ids: the account invoice refund’s ID or list of IDs
100
101 """
102 inv_obj = self.pool.get('account.invoice')
103 reconcile_obj = self.pool.get('account.move.reconcile')
104 account_m_line_obj = self.pool.get('account.move.line')
105 mod_obj = self.pool.get('ir.model.data')
106 act_obj = self.pool.get('ir.actions.act_window')
107 wf_service = netsvc.LocalService('workflow')
108 inv_tax_obj = self.pool.get('account.invoice.tax')
109 inv_line_obj = self.pool.get('account.invoice.line')
110 res_users_obj = self.pool.get('res.users')
111 if context is None:
112 context = {}
113
114 for form in self.read(cr, uid, ids, context=context):
115 created_inv = []
116 date = False
117 period = False
118 description = False
119 company = res_users_obj.browse(cr, uid, uid, context=context).company_id
120 journal_id = form.get('journal_id', False)
121 for inv in inv_obj.browse(cr, uid, context.get('active_ids'), context=context):
122 if inv.state in ['draft', 'proforma2', 'cancel']:
123 raise osv.except_osv(_('Error !'), _('Can not create a debit note from draft/proforma/cancel invoice.'))
124 if inv.reconciled and mode in ('cancel', 'modify'):
125 raise osv.except_osv(_('Error !'), _('Can not create a debit note from invoice which is already reconciled, invoice should be unreconciled first. You can only Refund or Debit this invoice'))
126 if inv.type not in ['in_invoice', 'out_invoice']:
127 raise osv.except_osv(_('Error !'), _('Can not make a debit note on a refund invoice.'))
128 if form['period']:
129 period = form['period']
130 else:
131 #Take period from the current date
132 #period = inv.period_id and inv.period_id.id or False
133 period = self._get_period(cr, uid, context)
134
135 if not journal_id:
136 journal_id = inv.journal_id.id
137
138 if form['date']:
139 date = form['date']
140 if not form['period']:
141 cr.execute("select name from ir_model_fields \
142 where model = 'account.period' \
143 and name = 'company_id'")
144 result_query = cr.fetchone()
145 if result_query:
146 #in multi company mode
147 cr.execute("""select p.id from account_fiscalyear y, account_period p where y.id=p.fiscalyear_id \
148 and date(%s) between p.date_start AND p.date_stop and y.company_id = %s limit 1""", (date, company.id,))
149 else:
150 #in mono company mode
151 cr.execute("""SELECT id
152 from account_period where date(%s)
153 between date_start AND date_stop \
154 limit 1 """, (date,))
155 res = cr.fetchone()
156 if res:
157 period = res[0]
158 else:
159 #Take current date
160 #date = inv.date_invoice
161 date = time.strftime('%Y-%m-%d')
162 if form['description']:
163 description = form['description']
164 else:
165 description = inv.name
166
167 if not period:
168 raise osv.except_osv(_('Data Insufficient !'), \
169 _('No Period found on Invoice!'))
170
171 #we get original data of invoice to create a new invoice that is the copy of the original
172 invoice = inv_obj.read(cr, uid, [inv.id],
173 ['name', 'type', 'number', 'reference',
174 'comment', 'date_due', 'partner_id',
175 'address_contact_id', 'address_invoice_id',
176 'partner_insite', 'partner_contact',
177 'partner_ref', 'payment_term', 'account_id',
178 'currency_id', 'invoice_line', 'tax_line',
179 'journal_id', 'period_id'], context=context)
180 invoice = invoice[0]
181 del invoice['id']
182 invoice_lines = []
183 tax_lines = []
184 #Add origin, parent and comment values
185 orig = self._get_orig(cr, uid, inv, invoice['reference'], context)
186 invoice.update({
187 'type': inv.type,
188 'date_invoice': date,
189 'state': 'draft',
190 'number': False,
191 'invoice_line': invoice_lines,
192 'tax_line': tax_lines,
193 'period_id': period,
194 'parent_id':inv.id,
195 'name': description,
196 'origin': orig,
197 'comment':form['comment']
198 })
199 #take the id part of the tuple returned for many2one fields
200 for field in ('address_contact_id', 'address_invoice_id', 'partner_id',
201 'account_id', 'currency_id', 'payment_term', 'journal_id'):
202 invoice[field] = invoice[field] and invoice[field][0]
203 # create the new invoice
204 inv_id = inv_obj.create(cr, uid, invoice, {})
205 # we compute due date
206 if inv.payment_term.id:
207 data = inv_obj.onchange_payment_term_date_invoice(cr, uid, [inv_id], inv.payment_term.id, date)
208 if 'value' in data and data['value']:
209 inv_obj.write(cr, uid, [inv_id], data['value'])
210 created_inv.append(inv_id)
211 #we get the view id
212 if inv.type in ('out_invoice', 'out_refund'):
213 xml_id = 'action_invoice_tree1'
214 else:
215 xml_id = 'action_invoice_tree2'
216 #we get the model
217 result = mod_obj.get_object_reference(cr, uid, 'account', xml_id)
218 id = result and result[1] or False
219 # we read the act window
220 result = act_obj.read(cr, uid, id, context=context)
221 # we add the new invoices into domain list
222 invoice_domain = eval(result['domain'])
223 invoice_domain.append(('id', 'in', created_inv))
224 result['domain'] = invoice_domain
225 return result
226
227 def invoice_debit(self, cr, uid, ids, context=None):
228 return self.compute_debit(cr, uid, ids, context=context)
229
230
231account_invoice_debit()
232
233# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
0234
=== added file 'l10n_ve_fiscal_requirements/wizard/account_invoice_debit_view.xml'
--- l10n_ve_fiscal_requirements/wizard/account_invoice_debit_view.xml 1970-01-01 00:00:00 +0000
+++ l10n_ve_fiscal_requirements/wizard/account_invoice_debit_view.xml 2011-11-03 23:12:26 +0000
@@ -0,0 +1,43 @@
1<?xml version="1.0" encoding="utf-8"?>
2<openerp>
3 <data>
4
5 <record id="view_account_invoice_debit" model="ir.ui.view">
6 <field name="name">account.invoice.debit.form</field>
7 <field name="model">account.invoice.debit</field>
8 <field name="type">form</field>
9 <field name="arch" type="xml">
10 <form string="Debit Note">
11 <separator string="Debit Note Options" colspan="4"/>
12 <group colspan="4" >
13 <field name="description"/>
14 <field name="journal_id" widget='selection'/>
15 <field name="date"/>
16 <field name="period"/>
17 <field name="comment" colspan="4"/>
18 </group>
19 <separator colspan="4"/>
20 <group col="4" colspan="4" fill="1">
21 <label align="0.0" width="300" string="Debit Invoice: Creates the debit note invoice, ready for editing."/>
22 </group>
23 <separator colspan="4"/>
24 <group colspan="4" col="6">
25 <button icon="gtk-cancel" special="cancel" string="Cancel"/>
26 <button string='Debit Note' icon="gtk-execute" name="invoice_debit" type="object"/>
27 </group>
28 </form>
29 </field>
30 </record>
31
32 <record id="action_account_invoice_debit" model="ir.actions.act_window">
33 <field name="name">Debit Note</field>
34 <field name="res_model">account.invoice.debit</field>
35 <field name="view_type">form</field>
36 <field name="view_mode">tree,form</field>
37 <field name="view_id" ref="view_account_invoice_debit"/>
38 <field name="target">new</field>
39 </record>
40
41
42 </data>
43</openerp>
044
=== added file 'l10n_ve_fiscal_requirements/wizard/account_invoice_refund.py'
--- l10n_ve_fiscal_requirements/wizard/account_invoice_refund.py 1970-01-01 00:00:00 +0000
+++ l10n_ve_fiscal_requirements/wizard/account_invoice_refund.py 2011-11-03 23:12:26 +0000
@@ -0,0 +1,235 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22import time
23
24from osv import fields, osv
25from tools.translate import _
26import netsvc
27
28class account_invoice_refund(osv.osv_memory):
29
30 """Refunds invoice"""
31 _inherit = 'account.invoice.refund'
32
33 def _get_journal(self, cr, uid, context=None):
34 obj_journal = self.pool.get('account.journal')
35 if context is None:
36 context = {}
37 journal = obj_journal.search(cr, uid, [('type', '=', 'sale_refund')])
38 if context.get('type', False):
39 if context['type'] in ('in_invoice', 'in_refund'):
40 journal = obj_journal.search(cr, uid, [('type', '=', 'purchase_refund')])
41 return journal and journal[0] or False
42
43
44 def fields_view_get(self, cr, uid, view_id=None, view_type=False, context=None, toolbar=False, submenu=False):
45 journal_obj = self.pool.get('account.journal')
46 res = super(account_invoice_refund,self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
47 type = context.get('journal_type', 'sale_refund')
48 if type in ('sale', 'sale_refund'):
49 type = 'sale_refund'
50 else:
51 type = 'purchase_refund'
52 for field in res['fields']:
53 if field == 'journal_id':
54 journal_select = journal_obj._name_search(cr, uid, '', [('type', '=', type)], context=context, limit=None, name_get_uid=1)
55 res['fields'][field]['selection'] = journal_select
56 return res
57
58 def _get_period(self, cr, uid, context={}):
59 """
60 Return default account period value
61 """
62 account_period_obj = self.pool.get('account.period')
63 ids = account_period_obj.find(cr, uid, context=context)
64 period_id = False
65 if ids:
66 period_id = ids[0]
67 return period_id
68
69 def _get_orig(self, cr, uid, inv, ref, context={}):
70 """
71 Return default origin value
72 """
73 nro_ref = ref
74 if inv.type == 'out_invoice':
75 nro_ref = inv.number
76 orig = 'Devolucion FACT:' +(nro_ref or '') + '- DE FECHA:' + (inv.date_invoice or '') + (' TOTAL:' + str(inv.amount_total) or '')
77 return orig
78
79 def compute_refund(self, cr, uid, ids, mode='refund', context=None):
80 """
81 @param cr: the current row, from the database cursor,
82 @param uid: the current user’s ID for security checks,
83 @param ids: the account invoice refund’s ID or list of IDs
84
85 """
86 inv_obj = self.pool.get('account.invoice')
87 reconcile_obj = self.pool.get('account.move.reconcile')
88 account_m_line_obj = self.pool.get('account.move.line')
89 mod_obj = self.pool.get('ir.model.data')
90 act_obj = self.pool.get('ir.actions.act_window')
91 wf_service = netsvc.LocalService('workflow')
92 inv_tax_obj = self.pool.get('account.invoice.tax')
93 inv_line_obj = self.pool.get('account.invoice.line')
94 res_users_obj = self.pool.get('res.users')
95 if context is None:
96 context = {}
97
98 for form in self.read(cr, uid, ids, context=context):
99 created_inv = []
100 date = False
101 period = False
102 description = False
103 company = res_users_obj.browse(cr, uid, uid, context=context).company_id
104 journal_id = form.get('journal_id', False)
105 for inv in inv_obj.browse(cr, uid, context.get('active_ids'), context=context):
106 if inv.state in ['draft', 'proforma2', 'cancel']:
107 raise osv.except_osv(_('Error !'), _('Can not %s draft/proforma/cancel invoice.') % (mode))
108 if inv.reconciled and mode in ('cancel', 'modify'):
109 raise osv.except_osv(_('Error !'), _('Can not %s invoice which is already reconciled, invoice should be unreconciled first. You can only Refund this invoice') % (mode))
110 if form['period']:
111 period = form['period']
112 else:
113 #Take period from the current date
114 #period = inv.period_id and inv.period_id.id or False
115 period = self._get_period(cr, uid, context)
116
117 if not journal_id:
118 journal_id = inv.journal_id.id
119
120 if form['date']:
121 date = form['date']
122 if not form['period']:
123 cr.execute("select name from ir_model_fields \
124 where model = 'account.period' \
125 and name = 'company_id'")
126 result_query = cr.fetchone()
127 if result_query:
128 cr.execute("""select p.id from account_fiscalyear y, account_period p where y.id=p.fiscalyear_id \
129 and date(%s) between p.date_start AND p.date_stop and y.company_id = %s limit 1""", (date, company.id,))
130 else:
131 cr.execute("""SELECT id
132 from account_period where date(%s)
133 between date_start AND date_stop \
134 limit 1 """, (date,))
135 res = cr.fetchone()
136 if res:
137 period = res[0]
138 else:
139 #Take current date
140 #date = inv.date_invoice
141 date = time.strftime('%Y-%m-%d')
142 if form['description']:
143 description = form['description']
144 else:
145 description = inv.name
146
147 if not period:
148 raise osv.except_osv(_('Data Insufficient !'), \
149 _('No Period found on Invoice!'))
150
151 refund_id = inv_obj.refund(cr, uid, [inv.id], date, period, description, journal_id)
152 refund = inv_obj.browse(cr, uid, refund_id[0], context=context)
153 #Add parent invoice
154 inv_obj.write(cr, uid, [refund.id], {'date_due': date,
155 'check_total': inv.check_total,'parent_id':inv.id})
156 inv_obj.button_compute(cr, uid, refund_id)
157
158 created_inv.append(refund_id[0])
159 if mode in ('cancel', 'modify'):
160 movelines = inv.move_id.line_id
161 to_reconcile_ids = {}
162 for line in movelines:
163 if line.account_id.id == inv.account_id.id:
164 to_reconcile_ids[line.account_id.id] = [line.id]
165 if type(line.reconcile_id) != osv.orm.browse_null:
166 reconcile_obj.unlink(cr, uid, line.reconcile_id.id)
167 wf_service.trg_validate(uid, 'account.invoice', \
168 refund.id, 'invoice_open', cr)
169 refund = inv_obj.browse(cr, uid, refund_id[0], context=context)
170 for tmpline in refund.move_id.line_id:
171 if tmpline.account_id.id == inv.account_id.id:
172 to_reconcile_ids[tmpline.account_id.id].append(tmpline.id)
173 for account in to_reconcile_ids:
174 account_m_line_obj.reconcile(cr, uid, to_reconcile_ids[account],
175 writeoff_period_id=period,
176 writeoff_journal_id = inv.journal_id.id,
177 writeoff_acc_id=inv.account_id.id
178 )
179 if mode == 'modify':
180 invoice = inv_obj.read(cr, uid, [inv.id],
181 ['name', 'type', 'number', 'reference',
182 'comment', 'date_due', 'partner_id',
183 'address_contact_id', 'address_invoice_id',
184 'partner_insite', 'partner_contact',
185 'partner_ref', 'payment_term', 'account_id',
186 'currency_id', 'invoice_line', 'tax_line',
187 'journal_id', 'period_id'], context=context)
188 invoice = invoice[0]
189 del invoice['id']
190 invoice_lines = inv_line_obj.read(cr, uid, invoice['invoice_line'], context=context)
191 invoice_lines = inv_obj._refund_cleanup_lines(cr, uid, invoice_lines)
192 tax_lines = inv_tax_obj.read(cr, uid, invoice['tax_line'], context=context)
193 tax_lines = inv_obj._refund_cleanup_lines(cr, uid, tax_lines)
194 #Add origin value
195 orig = self._get_orig(cr, uid, inv, invoice['reference'], context)
196 invoice.update({
197 'type': inv.type,
198 'date_invoice': date,
199 'state': 'draft',
200 'number': False,
201 'invoice_line': invoice_lines,
202 'tax_line': tax_lines,
203 'period_id': period,
204 'name': description,
205 'origin': orig,
206 })
207 for field in ('address_contact_id', 'address_invoice_id', 'partner_id',
208 'account_id', 'currency_id', 'payment_term', 'journal_id'):
209 invoice[field] = invoice[field] and invoice[field][0]
210 inv_id = inv_obj.create(cr, uid, invoice, {})
211 if inv.payment_term.id:
212 data = inv_obj.onchange_payment_term_date_invoice(cr, uid, [inv_id], inv.payment_term.id, date)
213 if 'value' in data and data['value']:
214 inv_obj.write(cr, uid, [inv_id], data['value'])
215 created_inv.append(inv_id)
216 if inv.type in ('out_invoice', 'out_refund'):
217 xml_id = 'action_invoice_tree3'
218 else:
219 xml_id = 'action_invoice_tree4'
220 result = mod_obj.get_object_reference(cr, uid, 'account', xml_id)
221 id = result and result[1] or False
222 result = act_obj.read(cr, uid, id, context=context)
223 invoice_domain = eval(result['domain'])
224 invoice_domain.append(('id', 'in', created_inv))
225 result['domain'] = invoice_domain
226 return result
227
228 def invoice_refund(self, cr, uid, ids, context=None):
229 data_refund = self.read(cr, uid, ids, [],context=context)[0]['filter_refund']
230 return self.compute_refund(cr, uid, ids, data_refund, context=context)
231
232
233account_invoice_refund()
234
235# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: