-
Notifications
You must be signed in to change notification settings - Fork 8
/
invoice.py
179 lines (165 loc) · 6.75 KB
/
invoice.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# -*- coding: utf-8 -*-
##############################################################################
#
# fiscal_printer
# Copyright (C) 2014 No author.
# No email
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import re
from openerp import netsvc
from openerp.osv import osv, fields
from openerp.tools.translate import _
_vat = lambda x: x.tax_code_id.parent_id.name == 'IVA'
document_type_map = {
"DNI": "D",
"CUIL": "L",
"CUIT": "T",
"CPF": "C",
"CIB": "C",
"CIK": "C",
"CIX": "C",
"CIW": "C",
"CIE": "C",
"CIY": "C",
"CIM": "C",
"CIF": "C",
"CIA": "C",
"CIJ": "C",
"CID": "C",
"CIS": "C",
"CIG": "C",
"CIT": "C",
"CIH": "C",
"CIU": "C",
"CIP": "C",
"CIN": "C",
"CIQ": "C",
"CIL": "C",
"CIR": "C",
"CIZ": "C",
"CIV": "C",
"PASS": "P",
"LC": "V",
"LE": "E",
};
responsability_map = {
"IVARI": "I", # Inscripto,
"IVARNI": "N", # No responsable,
"RM": "M", # Monotributista,
"IVAE": "E", # Exento,
"NC": "U", # No categorizado,
"CF": "F", # Consumidor final,
"RMS": "T", # Monotributista social,
"RMTIP": "P", # Monotributista trabajador independiente promovido.
}
class invoice(osv.osv):
""""""
_name = 'account.invoice'
_inherits = { }
_inherit = [ 'account.invoice' ]
def action_fiscal_printer(self, cr, uid, ids, context=None):
picking_obj = self.pool.get('stock.picking')
user_obj = self.pool.get('res.users')
r = {}
if len(ids) > 1:
raise osv.except_osv(_(u'Cancelling Validation'),
_(u'Please, validate one ticket at time.'))
return False
for inv in self.browse(cr, uid, ids, context):
if inv.journal_id.use_fiscal_printer:
journal = inv.journal_id
ticket={
"turist_ticket": False,
"debit_note": False,
"partner": {
"name": inv.partner_id.name,
"name_2": "",
"address": inv.partner_id.street,
"address_2": inv.partner_id.city,
"address_3": inv.partner_id.country_id.name,
"document_type": document_type_map.get(inv.partner_id.document_type_id.code, "D"),
"document_number": inv.partner_id.document_number,
"responsability": responsability_map.get(inv.partner_id.responsability_id.code, "F"),
},
"related_document": (picking_obj.search_read(cr, uid, [('origin','=',inv.origin)], ["name"]) +
[{'name': _("No picking")}])[0]['name'],
"related_document_2": inv.origin or "",
"turist_check": "",
"lines": [ ],
"cut_paper": True,
"electronic_answer": False,
"print_return_attribute": False,
"current_account_automatic_pay": False,
"print_quantities": True,
"tail_no": 1 if inv.user_id.name else 0,
"tail_text": _("Saleman: %s") % inv.user_id.name if inv.user_id.name else "",
"tail_no_2": 0,
"tail_text_2": "",
"tail_no_3": 0,
"tail_text_3": "",
}
for line in inv.invoice_line:
ticket["lines"].append({
"item_action": "sale_item",
"as_gross": False,
"send_subtotal": True,
"check_item": False,
"collect_type": "q",
"large_label": "",
"first_line_label": "",
"description": "",
"description_2": "",
"description_3": "",
"description_4": "",
"item_description": line.name,
"quantity": line.quantity,
"unit_price": line.price_unit,
"vat_rate": ([ tax.amount*100 for tax in line.invoice_line_tax_id.filtered(_vat)]+[0.0])[0],
"fixed_taxes": 0,
"taxes_rate": 0
})
if line.discount > 0: ticket["lines"].append({
"item_action": "discount_item",
"as_gross": False,
"send_subtotal": True,
"check_item": False,
"collect_type": "q",
"large_label": "",
"first_line_label": "",
"description": "",
"description_2": "",
"description_3": "",
"description_4": "",
"item_description": "%5.2f%%" % line.discount,
"quantity": line.quantity,
"unit_price": line.price_unit * (line.discount/100.),
"vat_rate": ([ tax.amount*100 for tax in line.invoice_line_tax_id.filtered(_vat)]+[0.0])[0],
"fixed_taxes": 0,
"taxes_rate": 0
})
r = journal.make_fiscal_ticket(ticket)[inv.journal_id.id]
if r and 'error' not in r:
import pdb; pdb.set_trace()
return True
elif r and 'error' in r:
raise osv.except_osv(_(u'Cancelling Validation'),
_('Error: %s') % r['error'])
else:
raise osv.except_osv(_(u'Cancelling Validation'),
_(u'Unknown error.'))
invoice()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: