1
# -*- encoding: utf-8 -*-
2
from osv import fields, osv
5
class account_move_line(osv.osv):
7
def search(self, cr, user, args, offset=0, limit=None, order=None, context=None, count=False):
8
# will check if the partner/account exists in statement lines if not then display all partner's account.move.line
10
if (item[0] in ('partner_id','account_id')) and (not item[2]):
11
args.pop(args.index(item))
13
return super(account_move_line,self).search(cr, user, args, offset, limit, order, context, count)
15
_inherit = "account.move.line"
16
_description = "account.move.line"
21
class account_invoice(osv.osv):
23
_inherit = "account.invoice"
25
'dept':fields.many2one('hr.department','Department'),
26
'invoice_special':fields.boolean('Special Invoice'),
27
'internal_note': fields.text('Internal Note'),
31
def action_move_create(self, cr, uid, ids, context=None):
33
move_obj = self.pool.get('account.move')
34
move_line_obj = self.pool.get('account.move.line')
35
data_invoice = self.browse(cr,uid,ids[0])
36
#raise an error if one of the account_invoice_line doesn't have an analytic entry
37
for line in data_invoice.invoice_line:
38
if not line.analytics_id:
41
raise osv.except_osv('Error!','Invoice line should have Analytic Distribution to create Analytic Entries.')
42
super(account_invoice, self).action_move_create(cr, uid, ids, context)
44
#create other move lines if the invoice_line is related to a check payment or an AWEX credence
45
for inv in self.browse(cr, uid, ids):
46
for item in self.pool.get('account.invoice.line').search(cr, uid, [('invoice_id','=',inv.id)]):
47
line = self.pool.get('account.invoice.line').browse(cr,uid, [item])[0]
48
if line.cci_special_reference:
50
if inv.type in ('in_invoice', 'in_refund'):
53
ref = self._convert_ref(cr, uid, inv.number)
54
temp = line.cci_special_reference.split('*')
57
obj_ref = self.pool.get(obj).browse(cr, uid, [obj_id])[0]
58
if obj == "event.registration":
59
#acc_id = self.pool.get('account.account').search(cr, uid, [('name','=','Creances AWEX - Cheques Formations et Cheques Langues')])[0]
60
journal_id = self.pool.get('account.journal').search(cr, uid, [('name','=','CFL Journal')])[0]
61
amount = obj_ref.check_amount
63
journal_id = self.pool.get('account.journal').search(cr, uid, [('name','=','AWEX Journal')])[0]
64
#acc_id = self.pool.get('account.account').search(cr, uid, [('name','=','Creances AWEX - Cheques Formations et Cheques Langues')])[0]
65
amount = obj_ref.awex_amount
66
acc_id = self.pool.get('account.journal').browse(cr, uid, [journal_id])[0].default_debit_account_id.id
69
'name': inv['name'] or '/',
72
'date_maturity': inv.date_due or False,
73
'amount_currency': False,
74
'currency_id': inv.currency_id.id or False,
79
'name': inv['name'] or '/',
81
'account_id': inv.account_id.id,
82
'date_maturity': inv.date_due or False,
83
'amount_currency': False,
84
'currency_id': inv.currency_id.id or False,
87
date = inv.date_invoice
88
part = inv.partner_id.id
89
new_lines = map(lambda x:(0,0,self.line_get_convert(cr, uid, x, part, date, context={})) ,iml)
90
for item in new_lines:
92
id1 = item[2]['credit']
94
journal = self.pool.get('account.journal').browse(cr, uid, journal_id)
95
if journal.sequence_id:
96
name = self.pool.get('ir.sequence').get_id(cr, uid, journal.sequence_id.id)
98
move = {'name': name, 'line_id': new_lines, 'journal_id': journal_id}
100
move['period_id'] = inv.period_id.id
102
i[2]['period_id'] = inv.period_id.id
103
move_id = move_obj.create(cr, uid, move)
104
move_obj.post(cr, uid, [move_id])
106
#this function could be improved in order to enable having more than one translation line per invoice
107
id1 = move_line_obj.search(cr, uid, [('move_id','=',move_id),('credit','<>',False)])[0]
108
id2 = move_line_obj.search(cr, uid, [('invoice','=',inv.id),('debit','<>',0)])[0]
109
move_line_obj.reconcile_partial(cr, uid, [id2,id1], 'manual', context=context)
113
#raise an error if the partner has the warning 'alert_others' when we choose him in the account_invoice form
114
def onchange_partner_id(self, cr, uid, ids, type, partner_id,date_invoice=False, payment_term=False, partner_bank_id=False):
117
data_partner = self.pool.get('res.partner').browse(cr,uid,partner_id)
118
inv_special=data_partner.invoice_special
119
if data_partner.alert_others:
120
raise osv.except_osv('Error!',data_partner.alert_explanation or 'Partner is not valid')
122
data=super(account_invoice,self).onchange_partner_id( cr, uid, ids, type, partner_id,date_invoice, payment_term, partner_bank_id)
123
data['value']['invoice_special']=inv_special
126
#raise an error when we try to invoice a membership product to a partner with the 'alert_membership' warning set to TRUE
127
def create(self, cr, uid, vals, *args, **kwargs):
131
inv_line_obj = self.pool.get('account.invoice.line')
132
if 'invoice_line' in vals and vals['invoice_line']:
133
for line in vals['invoice_line']:
134
if type(line[2])==type([]):
135
data_lines = inv_line_obj.browse(cr, uid, line[2])
136
for line in data_lines:
138
product_ids.append(line.product_id.id)
140
if line[2].has_key('product_id') and line[2]['product_id']:
141
product_ids.append(line[2]['product_id'])
142
if 'abstract_line_ids' in vals:
143
for lines in vals['abstract_line_ids']:
144
line_ids.append(lines[1])
145
data_lines = inv_line_obj.browse(cr, uid, line_ids)
146
for line in data_lines:
148
product_ids.append(line.product_id.id)
150
data_product = self.pool.get('product.product').browse(cr,uid,product_ids)
151
for product in data_product:
152
if product.membership:
154
if vals['partner_id']:
155
data_partner = self.pool.get('res.partner').browse(cr,uid,vals['partner_id'])
156
if data_partner.alert_membership and flag:
157
raise osv.except_osv('Error!',data_partner.alert_explanation or 'Partner is not valid')
158
return super(account_invoice,self).create(cr, uid, vals, *args, **kwargs)
160
#raise an error when we try to invoice a membership product to a partner with the 'alert_membership' warning set to TRUE
161
def write(self, cr, uid, ids,vals, *args, **kwargs):
163
a = super(account_invoice,self).write(cr, uid, ids,vals, *args, **kwargs)
165
data_inv = self.browse(cr,uid,ids[0])
166
for lines in data_inv.abstract_line_ids:
168
product_ids.append(lines.product_id.id)
170
data_product = self.pool.get('product.product').browse(cr,uid,product_ids)
171
for product in data_product:
172
if product.membership:
174
if data_inv.partner_id.alert_membership and flag:
175
raise osv.except_osv('Error!',data_inv.partner_id.alert_explanation or 'Partner is not valid')
181
class sale_order(osv.osv):
182
_inherit = "sale.order"
184
'dept' : fields.many2one('hr.department','Department'),
191
class account_invoice_line(osv.osv):
192
_inherit = "account.invoice.line"
194
'cci_special_reference' : fields.char('Special Reference', size=64),
197
'cci_special_reference': lambda *a : False,
199
account_invoice_line()
200
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: