[IMP]: improve voucher and voucher payment modules
bzr revid: mga@tinyerp.com-20100707150416-ww6f0b9256kn6q8b
This commit is contained in:
@@ -103,7 +103,7 @@ class account_voucher(osv.osv):
|
||||
|
||||
_name = 'account.voucher'
|
||||
_description = 'Accounting Voucher'
|
||||
_order = "date desc"
|
||||
_order = "id desc"
|
||||
_columns = {
|
||||
'name':fields.char('Name', size=256, required=True, readonly=True, states={'draft':[('readonly',False)]}),
|
||||
'type': fields.selection([
|
||||
@@ -211,7 +211,11 @@ class account_voucher(osv.osv):
|
||||
self.action_move_line_create(cr, uid, ids)
|
||||
self.write(cr, uid, ids, {'state':'posted'})
|
||||
return True
|
||||
|
||||
|
||||
def action_cancel_draft(self, cr, uid, ids, *args):
|
||||
self.write(cr, uid, ids, {'state':'draft'})
|
||||
return True
|
||||
|
||||
def cancel_voucher(self, cr, uid, ids, context={}):
|
||||
move_pool = self.pool.get('account.move')
|
||||
|
||||
@@ -228,10 +232,6 @@ class account_voucher(osv.osv):
|
||||
self.write(cr, uid, ids, res)
|
||||
return True
|
||||
|
||||
def action_cancel_draft(self, cr, uid, ids, *args):
|
||||
self.write(cr, uid, ids, {'state':'draft'})
|
||||
return True
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
vouchers = self.read(cr, uid, ids, ['state'])
|
||||
unlink_ids = []
|
||||
@@ -417,176 +417,52 @@ class account_voucher_line(osv.osv):
|
||||
'type': lambda *a: 'cr'
|
||||
}
|
||||
|
||||
def move_line_get(self, cr, uid, voucher_id, context={}):
|
||||
res = []
|
||||
|
||||
cur_obj = self.pool.get('res.currency')
|
||||
inv = self.pool.get('account.voucher').browse(cr, uid, voucher_id)
|
||||
company_currency = inv.company_id.currency_id.id
|
||||
cur = inv.currency_id
|
||||
|
||||
for line in inv.payment_ids:
|
||||
res.append(self.move_line_get_item(cr, uid, line, context))
|
||||
return res
|
||||
|
||||
def onchange_partner(self, cr, uid, ids, partner_id, ttype ,type1):
|
||||
vals = {}
|
||||
|
||||
if not partner_id:
|
||||
return {'value' : {'account_id' : False, 'type' : False ,'amount':False}}
|
||||
obj = self.pool.get('res.partner')
|
||||
vals.update({
|
||||
'account_id': False,
|
||||
'type': False ,
|
||||
'amount': False
|
||||
})
|
||||
return {
|
||||
'value' : vals
|
||||
}
|
||||
|
||||
partner_pool = self.pool.get('res.partner')
|
||||
account_id = False
|
||||
|
||||
partner = partner_pool.browse(cr, uid, partner_id)
|
||||
|
||||
if type1 in ('rec_voucher','bank_rec_voucher', 'journal_voucher'):
|
||||
account_id = obj.browse(cr, uid, partner_id).property_account_receivable
|
||||
balance = obj.browse(cr,uid,partner_id).credit
|
||||
account_id = partner.property_account_receivable.id
|
||||
balance = partner.credit
|
||||
ttype = 'cr'
|
||||
|
||||
elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') :
|
||||
account_id = obj.browse(cr, uid, partner_id).property_account_payable
|
||||
balance = obj.browse(cr,uid,partner_id).debit
|
||||
account_id = partner.property_account_payable.id
|
||||
balance = partner.debit
|
||||
ttype = 'dr'
|
||||
|
||||
elif type1 in ('journal_sale_vou') :
|
||||
account_id = obj.browse(cr, uid, partner_id).property_account_receivable
|
||||
balance = obj.browse(cr,uid,partner_id).credit
|
||||
account_id = partner.property_account_receivable.id
|
||||
balance = partner.credit
|
||||
ttype = 'dr'
|
||||
|
||||
elif type1 in ('journal_pur_voucher') :
|
||||
account_id = obj.browse(cr, uid, partner_id).property_account_payable
|
||||
balance = obj.browse(cr,uid,partner_id).debit
|
||||
account_id = partner.property_account_payable.id
|
||||
balance = partner.debit
|
||||
ttype = 'cr'
|
||||
|
||||
|
||||
vals.update({
|
||||
'account_id': account_id,
|
||||
'type': ttype,
|
||||
'amount':balance
|
||||
})
|
||||
|
||||
return {
|
||||
'value' : {'account_id' : account_id.id, 'type' : ttype, 'amount':balance}
|
||||
'value' : vals
|
||||
}
|
||||
|
||||
def onchange_amount(self, cr, uid, ids, partner_id, amount, type, type1):
|
||||
if not amount:
|
||||
return {'value' : {}}
|
||||
if partner_id:
|
||||
obj = self.pool.get('res.partner')
|
||||
if type1 in ('rec_voucher', 'bank_rec_voucher', 'journal_voucher'):
|
||||
if amount < 0 :
|
||||
account_id = obj.browse(cr, uid, partner_id).property_account_payable
|
||||
type = 'dr'
|
||||
else:
|
||||
account_id = obj.browse(cr, uid, partner_id).property_account_receivable
|
||||
type = 'cr'
|
||||
|
||||
elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') :
|
||||
if amount < 0 :
|
||||
account_id = obj.browse(cr, uid, partner_id).property_account_receivable
|
||||
type = 'cr'
|
||||
else:
|
||||
account_id = obj.browse(cr, uid, partner_id).property_account_payable
|
||||
type = 'dr'
|
||||
|
||||
elif type1 in ('journal_sale_vou') :
|
||||
if amount < 0 :
|
||||
account_id = obj.browse(cr, uid, partner_id).property_account_payable
|
||||
type = 'cr'
|
||||
else:
|
||||
account_id = obj.browse(cr, uid, partner_id).property_account_receivable
|
||||
type = 'dr'
|
||||
|
||||
elif type1 in ('journal_pur_voucher') :
|
||||
if amount< 0 :
|
||||
account_id = obj.browse(cr, uid, partner_id).property_account_receivable
|
||||
type = 'dr'
|
||||
else:
|
||||
account_id = obj.browse(cr, uid, partner_id).property_account_payable
|
||||
type = 'cr'
|
||||
else:
|
||||
if type1 in ('rec_voucher', 'bank_rec_voucher', 'journal_voucher'):
|
||||
if amount < 0 :
|
||||
type = 'dr'
|
||||
else:
|
||||
type = 'cr'
|
||||
elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') :
|
||||
if amount < 0 :
|
||||
type = 'cr'
|
||||
else:
|
||||
type = 'dr'
|
||||
elif type1 in ('journal_sale_vou') :
|
||||
if amount < 0 :
|
||||
type = 'cr'
|
||||
else:
|
||||
type = 'dr'
|
||||
elif type1 in ('journal_pur_voucher') :
|
||||
if amount< 0 :
|
||||
type = 'dr'
|
||||
else:
|
||||
type = 'cr'
|
||||
|
||||
return {
|
||||
'value' : { 'type' : type , 'amount':amount}
|
||||
}
|
||||
|
||||
def onchange_type(self, cr, uid, ids, partner_id, amount, type, type1):
|
||||
if partner_id:
|
||||
obj = self.pool.get('res.partner')
|
||||
if type1 in ('rec_voucher','bank_rec_voucher', 'journal_voucher'):
|
||||
if type == 'dr' :
|
||||
account_id = obj.browse(cr, uid, partner_id).property_account_payable
|
||||
total=amount*(-1)
|
||||
else:
|
||||
account_id = obj.browse(cr, uid, partner_id).property_account_receivable
|
||||
total=amount*(-1)
|
||||
|
||||
elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') :
|
||||
if type == 'cr' :
|
||||
account_id = obj.browse(cr, uid, partner_id).property_account_receivable
|
||||
total=amount*(-1)
|
||||
else:
|
||||
account_id = obj.browse(cr, uid, partner_id).property_account_payable
|
||||
total=amount*(-1)
|
||||
|
||||
elif type1 in ('journal_sale_vou') :
|
||||
if type == 'cr' :
|
||||
account_id = obj.browse(cr, uid, partner_id).property_account_payable
|
||||
total=amount*(-1)
|
||||
else:
|
||||
account_id = obj.browse(cr, uid, partner_id).property_account_receivable
|
||||
total=amount*(-1)
|
||||
elif type1 in ('journal_pur_voucher') :
|
||||
if type == 'dr' :
|
||||
account_id = obj.browse(cr, uid, partner_id).property_account_receivable
|
||||
total=amount*(-1)
|
||||
else:
|
||||
account_id = obj.browse(cr, uid, partner_id).property_account_payable
|
||||
total=amount*(-1)
|
||||
else:
|
||||
if type1 in ('rec_voucher','bank_rec_voucher', 'journal_voucher'):
|
||||
if type == 'dr' :
|
||||
total=amount*(-1)
|
||||
else:
|
||||
total=amount*(-1)
|
||||
|
||||
elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') :
|
||||
if type == 'cr' :
|
||||
total=amount*(-1)
|
||||
else:
|
||||
total=amount*(-1)
|
||||
|
||||
elif type1 in ('journal_sale_vou') :
|
||||
if type == 'cr' :
|
||||
total=amount*(-1)
|
||||
else:
|
||||
total=amount*(-1)
|
||||
elif type1 in ('journal_pur_voucher') :
|
||||
if type == 'dr' :
|
||||
total=amount*(-1)
|
||||
else:
|
||||
total=amount*(-1)
|
||||
|
||||
return {
|
||||
'value' : {'type' : type , 'amount':total}
|
||||
}
|
||||
|
||||
def move_line_get_item(self, cr, uid, line, context={}):
|
||||
return {
|
||||
'type':'src',
|
||||
'name': line.name[:64],
|
||||
'amount':line.amount,
|
||||
'account_id':line.account_id.id,
|
||||
'partner_id':line.partner_id.id or False ,
|
||||
'account_analytic_id':line.account_analytic_id.id or False,
|
||||
'ref' : line.ref
|
||||
}
|
||||
|
||||
|
||||
account_voucher_line()
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
</group>
|
||||
<notebook colspan="4">
|
||||
<page string="Journal Entries">
|
||||
<field name="payment_ids" colspan="4" nolabel="1" height="260">
|
||||
<field name="payment_ids" colspan="4" nolabel="1" height="250">
|
||||
<tree string="Voucher Lines" editable="top">
|
||||
<field name="partner_id" on_change="onchange_partner(partner_id,type,parent.type)"/>
|
||||
<field name="account_id"/>
|
||||
@@ -48,15 +48,6 @@
|
||||
</field>
|
||||
<separator string="Narration" colspan="4"/>
|
||||
<field name="narration" colspan="4" nolabel="1" height="50"/>
|
||||
<group col="8" colspan="4">
|
||||
<field name="state"/>
|
||||
<button name="open_voucher" string="Pro-forma" states="draft" icon="terp-check"/>
|
||||
<button name="proforma_voucher" string="Create" states="proforma" icon="terp-document-new"/>
|
||||
<button name="recheck_voucher" string="Validate" states="recheck" icon="terp-check"/>
|
||||
<button name="audit_complete" string="Audit Pass" states="posted" icon="terp-check"/>
|
||||
<button name="cancel_voucher" string="Cancel" states="proforma,recheck,posted" icon="gtk-cancel"/>
|
||||
<button name="cancel_to_draft" states="cancel" string="Set to Draft" icon="terp-stock_effects-object-colorize"/>
|
||||
</group>
|
||||
</page>
|
||||
<page string="Other Info">
|
||||
<field name="company_id" select="1" widget="selection" groups="base.group_multi_company"/>
|
||||
@@ -67,6 +58,15 @@
|
||||
<field name="move_ids" colspan="4" nolabel="1" readonly="1"/>
|
||||
</page>
|
||||
</notebook>
|
||||
<group col="8" colspan="4">
|
||||
<field name="state"/>
|
||||
<button name="open_voucher" string="Pro-forma" states="draft" icon="terp-check"/>
|
||||
<button name="proforma_voucher" string="Create" states="proforma" icon="terp-document-new"/>
|
||||
<button name="recheck_voucher" string="Validate" states="recheck" icon="terp-check"/>
|
||||
<button name="audit_complete" string="Audit Pass" states="posted" icon="terp-check"/>
|
||||
<button name="cancel_voucher" string="Cancel" states="proforma,recheck,posted" icon="gtk-cancel"/>
|
||||
<button name="cancel_to_draft" states="cancel" string="Set to Draft" icon="terp-stock_effects-object-colorize"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -38,170 +38,127 @@ class account_voucher(osv.osv):
|
||||
|
||||
def action_move_line_create(self, cr, uid, ids, *args):
|
||||
|
||||
journal_pool = self.pool.get('account.journal')
|
||||
sequence_pool = self.pool.get('ir.sequence')
|
||||
move_pool = self.pool.get('account.move')
|
||||
move_line_pool = self.pool.get('account.move.line')
|
||||
analytic_pool = self.pool.get('account.analytic.line')
|
||||
currency_pool = self.pool.get('res.currency')
|
||||
invoice_pool = self.pool.get('account.invoice')
|
||||
|
||||
for inv in self.browse(cr, uid, ids):
|
||||
|
||||
if inv.move_id:
|
||||
continue
|
||||
|
||||
company_currency = inv.company_id.currency_id.id
|
||||
|
||||
line_ids = self.read(cr, uid, [inv.id], ['payment_ids'])[0]['payment_ids']
|
||||
ils = self.pool.get('account.voucher.line').read(cr, uid, line_ids)
|
||||
|
||||
iml = self._get_analytic_lines(cr, uid, inv.id)
|
||||
|
||||
diff_currency_p = inv.currency_id.id <> company_currency
|
||||
|
||||
total = 0
|
||||
if inv.type in ('pay_voucher', 'journal_voucher', 'rec_voucher','cont_voucher','bank_pay_voucher','bank_rec_voucher','journal_sale_voucher','journal_pur_voucher'):
|
||||
ref = inv.reference
|
||||
else:
|
||||
ref = self._convert_ref(cr, uid, inv.number)
|
||||
|
||||
date = inv.date
|
||||
total_currency = 0
|
||||
for i in iml:
|
||||
partner_id=i['partner_id']
|
||||
acc_id = i['account_id']
|
||||
if inv.currency_id.id != company_currency:
|
||||
i['currency_id'] = inv.currency_id.id
|
||||
i['amount_currency'] = i['amount']
|
||||
else:
|
||||
i['amount_currency'] = False
|
||||
i['currency_id'] = False
|
||||
if inv.type in ('rec_voucher','bank_rec_voucher','journal_pur_voucher','journal_voucher'):
|
||||
total += i['amount']
|
||||
total_currency += i['amount_currency'] or i['amount']
|
||||
i['amount'] = - i['amount']
|
||||
else:
|
||||
total -= i['amount']
|
||||
total_currency -= i['amount_currency'] or i['amount']
|
||||
|
||||
name = inv['name'] or '/'
|
||||
totlines = False
|
||||
|
||||
iml.append({
|
||||
'type': 'dest',
|
||||
'name': name,
|
||||
'amount': total or False,
|
||||
'account_id': acc_id,
|
||||
'amount_currency': diff_currency_p \
|
||||
and total_currency or False,
|
||||
'currency_id': diff_currency_p \
|
||||
and inv.currency_id.id or False,
|
||||
'ref': ref,
|
||||
'partner_id':partner_id or False,
|
||||
})
|
||||
|
||||
date = inv.date
|
||||
inv.amount=total
|
||||
|
||||
line = map(lambda x:(0,0,self.line_get_convert(cr, uid, x,date, context={})) ,iml)
|
||||
an_journal_id=inv.journal_id.analytic_journal_id.id
|
||||
journal_id = inv.journal_id.id
|
||||
|
||||
journal = self.pool.get('account.journal').browse(cr, uid, journal_id)
|
||||
ref = inv.reference
|
||||
|
||||
journal = journal_pool.browse(cr, uid, inv.journal_id.id)
|
||||
if journal.sequence_id:
|
||||
name = self.pool.get('ir.sequence').get_id(cr, uid, journal.sequence_id.id)
|
||||
|
||||
name = sequence_pool.get_id(cr, uid, journal.sequence_id.id)
|
||||
|
||||
move = {
|
||||
'name': name,
|
||||
'journal_id': journal_id,
|
||||
'voucher_type':inv.type,
|
||||
'narration' : inv.narration,
|
||||
'data':date
|
||||
'name' : name,
|
||||
'journal_id': journal.id,
|
||||
'type' : inv.type,
|
||||
'narration' : inv.narration and inv.narration or inv.name,
|
||||
'date':inv.date
|
||||
}
|
||||
|
||||
|
||||
if inv.period_id:
|
||||
move['period_id'] = inv.period_id.id
|
||||
for i in line:
|
||||
i[2]['period_id'] = inv.period_id.id
|
||||
move_id = self.pool.get('account.move').create(cr, uid, move)
|
||||
ref=move['name']
|
||||
amount=0.0
|
||||
#create the first line our self
|
||||
move.update({
|
||||
'period_id': inv.period_id.id
|
||||
})
|
||||
|
||||
move_id = move_pool.create(cr, uid, move)
|
||||
|
||||
#create the first line manually
|
||||
move_line = {
|
||||
'name': inv.name,
|
||||
'voucher_invoice' : iml and iml[0]['invoice'] and iml[0]['invoice'].id or False,
|
||||
'debit': False,
|
||||
'credit':False,
|
||||
'account_id': inv.account_id.id or False,
|
||||
'move_id':move_id ,
|
||||
'journal_id':journal_id ,
|
||||
'period_id':inv.period_id.id,
|
||||
'move_id': move_id ,
|
||||
'journal_id': inv.journal_id.id,
|
||||
'period_id': inv.period_id.id,
|
||||
'partner_id': False,
|
||||
'ref': ref,
|
||||
'date': date
|
||||
'date': inv.date
|
||||
}
|
||||
if diff_currency_p:
|
||||
amount_currency = currency_pool.compute(cr, uid, inv.currency_id.id, company_currency, inv.amount)
|
||||
inv.amount = amount_currency
|
||||
move_line.update({
|
||||
'amount_currency':amount_currency,
|
||||
'currency_id':inv.currency_id.id
|
||||
})
|
||||
|
||||
if inv.type in ('rec_voucher', 'bank_rec_voucher', 'journal_pur_voucher', 'journal_voucher'):
|
||||
move_line['debit'] = inv.amount
|
||||
else:
|
||||
move_line['credit'] = inv.amount * (-1)
|
||||
self.pool.get('account.move.line').create(cr, uid, move_line)
|
||||
id_mapping_dict = {}
|
||||
mline_ids = []
|
||||
for line in inv.voucher_line_ids:
|
||||
move_line['credit'] = inv.amount
|
||||
|
||||
line_ids = []
|
||||
line_ids += [move_line_pool.create(cr, uid, move_line)]
|
||||
for line in inv.payment_ids:
|
||||
amount=0.0
|
||||
move_line = {
|
||||
'name':line.name,
|
||||
'voucher_invoice' : iml and iml[0]['invoice'] and iml[0]['invoice'].id or False,
|
||||
'debit':False,
|
||||
'credit':False,
|
||||
'move_id':move_id,
|
||||
'account_id':line.account_id.id or False,
|
||||
'journal_id':journal_id ,
|
||||
'period_id':inv.period_id.id,
|
||||
'partner_id':line.partner_id.id or False,
|
||||
'ref':ref,
|
||||
'date':date
|
||||
}
|
||||
|
||||
if line.type == 'dr':
|
||||
move_line['debit'] = line.amount or False
|
||||
amount=line.amount
|
||||
elif line.type == 'cr':
|
||||
move_line['credit'] = line.amount or False
|
||||
amount=line.amount * (-1)
|
||||
ml_id=self.pool.get('account.move.line').create(cr, uid, move_line)
|
||||
id_mapping_dict[line.id] = ml_id
|
||||
|
||||
total = 0.0
|
||||
mline = self.pool.get('account.move.line')
|
||||
if line.invoice_id.id:
|
||||
invoice = self.pool.get('account.invoice').browse(cr, uid, line.invoice_id.id)
|
||||
src_account_id = invoice.account_id.id
|
||||
cr.execute('select id from account_move_line where move_id in ('+str(invoice.move_id.id)+')')
|
||||
temp_ids = map(lambda x: x[0], cr.fetchall())
|
||||
temp_ids.append(ml_id)
|
||||
mlines = mline.browse(cr, uid, temp_ids)
|
||||
for ml in mlines:
|
||||
if ml.account_id.id==src_account_id:
|
||||
mline_ids.append(ml.id)
|
||||
total += (ml.debit or 0.0) - (ml.credit or 0.0)
|
||||
#end if line.invoice_id.id:
|
||||
if inv.narration:
|
||||
line.name=inv.narration
|
||||
else:
|
||||
line.name=line.name
|
||||
|
||||
'name': line.name,
|
||||
'debit': False,
|
||||
'credit': False,
|
||||
'account_id': line.account_id.id or False,
|
||||
'move_id': move_id ,
|
||||
'journal_id': inv.journal_id.id,
|
||||
'period_id': inv.period_id.id,
|
||||
'partner_id': line.partner_id.id or False,
|
||||
'ref': ref,
|
||||
'date': inv.date,
|
||||
'analytic_account_id': False
|
||||
}
|
||||
|
||||
if diff_currency_p:
|
||||
amount_currency = currency_pool.compute(cr, uid, inv.currency_id.id, company_currency, line.amount)
|
||||
line.amount = amount_currency
|
||||
move_line.update({
|
||||
'amount_currency':amount_currency,
|
||||
'currency_id':inv.currency_id.id
|
||||
})
|
||||
|
||||
if line.account_analytic_id:
|
||||
an_line = {
|
||||
'name':line.name,
|
||||
'date':date,
|
||||
'amount':amount,
|
||||
'account_id':line.account_analytic_id.id or False,
|
||||
'move_id':ml_id,
|
||||
'journal_id':an_journal_id ,
|
||||
'general_account_id':line.account_id.id,
|
||||
'ref':ref
|
||||
}
|
||||
self.pool.get('account.analytic.line').create(cr, uid, an_line)
|
||||
if mline_ids:
|
||||
self.pool.get('account.move.line').reconcile_partial(cr, uid, mline_ids, 'manual', context={})
|
||||
self.write(cr, uid, [inv.id], {'move_id': move_id})
|
||||
obj=self.pool.get('account.move').browse(cr, uid, move_id)
|
||||
|
||||
for line in obj.line_id :
|
||||
cr.execute('insert into voucher_id (account_id,rel_account_move) values (%d, %d)',(int(ids[0]),int(line.id)))
|
||||
|
||||
return True
|
||||
move_line.update({
|
||||
'analytic_account_id':line.account_analytic_id.id
|
||||
})
|
||||
|
||||
if line.type == 'dr':
|
||||
move_line.update({
|
||||
'debit': line.amount or False
|
||||
})
|
||||
amount = line.amount
|
||||
|
||||
elif line.type == 'cr':
|
||||
move_line.update({
|
||||
'credit': line.amount or False
|
||||
})
|
||||
amount = line.amount
|
||||
|
||||
if line.invoice_id:
|
||||
move_line.update({
|
||||
'invoice_id':line.invoice_id.id
|
||||
})
|
||||
invoice_pool.pay_and_reconcile(cr, uid, [line.invoice_id.id], amount, inv.account_id.id, inv.period_id.id, inv.journal_id.id, False, False, False)
|
||||
|
||||
move_line_id = move_line_pool.create(cr, uid, move_line)
|
||||
line_ids += [move_line_id]
|
||||
|
||||
rec = {
|
||||
'move_id': move_id,
|
||||
'move_ids':[(6, 0,line_ids)]
|
||||
}
|
||||
self.write(cr, uid, [inv.id], rec)
|
||||
|
||||
return True
|
||||
|
||||
account_voucher()
|
||||
|
||||
@@ -222,18 +179,29 @@ class account_voucher_line(osv.osv):
|
||||
res['invoice'] = line.invoice_id or False
|
||||
return res
|
||||
|
||||
def onchange_invoice_id(self, cr, uid, ids, invoice_id, context={}):
|
||||
lines = []
|
||||
if 'lines' in self.voucher_context:
|
||||
lines = [x[2] for x in self.voucher_context['lines']]
|
||||
def onchange_invoice_id(self, cr, uid, ids, invoice_id, currency_id):
|
||||
currency_pool = self.pool.get('res.currency')
|
||||
invoice_pool = self.pool.get('account.invoice')
|
||||
res = {
|
||||
'amount':0.0
|
||||
}
|
||||
if not invoice_id:
|
||||
return {'value':{}}
|
||||
return {
|
||||
'value':res
|
||||
}
|
||||
else:
|
||||
invoice_obj = self.pool.get('account.invoice').browse(cr, uid, invoice_id, context)
|
||||
residual = invoice_obj.residual
|
||||
same_invoice_amounts = [x['amount'] for x in lines if x['invoice_id']==invoice_id]
|
||||
residual -= sum(same_invoice_amounts)
|
||||
return {'value' : {'amount':residual}}
|
||||
invoice = invoice_pool.browse(cr, uid, invoice_id)
|
||||
residual = invoice.residual
|
||||
if invoice.currency_id.id != currency_id:
|
||||
residual = currency_pool.compute(cr, uid, invoice.currency_id.id, currency_id, invoice.residual)
|
||||
|
||||
res.update({
|
||||
'amount': residual
|
||||
})
|
||||
|
||||
return {
|
||||
'value':res
|
||||
}
|
||||
|
||||
def onchange_line_account(self, cr, uid, ids, account_id, type, type1):
|
||||
if not account_id:
|
||||
|
||||
@@ -1,21 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<!--
|
||||
Voucher line extension
|
||||
-->
|
||||
<record id="view_voucher_form" model="ir.ui.view">
|
||||
<field name="name">account.voucher.line.form.inherit</field>
|
||||
<field name="model">account.voucher.line</field>
|
||||
<field name="type">form</field>
|
||||
<field name="inherit_id" ref="account_voucher.view_voucher_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="name" position="after">
|
||||
<field name="invoice_id" on_change="onchange_invoice_id(invoice_id)" domain="[('partner_id','=',partner_id),('state','=','open')]"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_voucher_form" model="ir.ui.view">
|
||||
<field name="name">account.voucher.form.inherit</field>
|
||||
<field name="model">account.voucher</field>
|
||||
@@ -23,12 +8,12 @@
|
||||
<field name="inherit_id" ref="account_voucher.view_voucher_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="payment_ids" position="replace">
|
||||
<field name="voucher_line_ids" default_get="{'lines': voucher_line_ids }" colspan="4" nolabel="1" height="275">
|
||||
<field name="voucher_line_ids" default_get="{'lines': voucher_line_ids}" colspan="4" nolabel="1" height="275">
|
||||
<tree string="Voucher Lines" editable="top">
|
||||
<field name="partner_id" on_change="onchange_partner(partner_id, type, parent.type)"/>
|
||||
<field name="account_id" on_change="onchange_line_account(account_id, type, parent.type)"/>
|
||||
<field name="name"/>
|
||||
<field name="invoice_id" on_change="onchange_invoice_id(invoice_id)" domain="[('partner_id','=',partner_id),('state','=','open'),('residual','>',0.0)]"/>
|
||||
<field name="invoice_id" on_change="onchange_invoice_id(invoice_id, parent.currency_id)" domain="[('partner_id','=',partner_id),('state','=','open'),('residual','>',0.0)]"/>
|
||||
<field name="type"/>
|
||||
<field name="amount"/>
|
||||
<field name="account_analytic_id"/>
|
||||
|
||||
@@ -27,20 +27,20 @@ class account_voucher_unreconcile(osv.osv_memory):
|
||||
def trans_unrec(self, cr, uid, ids, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
obj_voucher = self.pool.get('account.voucher')
|
||||
obj_reconcile = self.pool.get('account.move.reconcile')
|
||||
voucher_pool = self.pool.get('account.voucher')
|
||||
reconcile_pool = self.pool.get('account.move.reconcile')
|
||||
if context.get('active_id'):
|
||||
voucher = obj_voucher.browse(cr, uid, context.get('active_id'), context=context)
|
||||
recs = []
|
||||
for line in voucher.move_ids:
|
||||
if line.reconcile_id:
|
||||
recs = [line.reconcile_id.id]
|
||||
|
||||
|
||||
for rec in recs:
|
||||
obj_reconcile.unlink(cr, uid, rec)
|
||||
|
||||
|
||||
return {}
|
||||
|
||||
account_voucher_unreconcile()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -2,28 +2,36 @@
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="view_account_voucher_unreconcile" model="ir.ui.view">
|
||||
<record id="view_account_voucher_unreconcile" model="ir.ui.view">
|
||||
<field name="name">Account voucher unreconcile</field>
|
||||
<field name="model">account.voucher.unreconcile</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Unreconciliation">
|
||||
<separator colspan="4" string="Unreconciliation transactions" />
|
||||
<label string="If you unreconciliate transactions, you must also verify all the actions that are linked to those transactions because they will not be disable" colspan="2"/>
|
||||
<separator colspan="4"/>
|
||||
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
|
||||
<button name="trans_unrec" default_focus="1" string="Unreconcile" type="object" icon="gtk-ok"/>
|
||||
<separator colspan="4" string="Unreconciliation transactions" />
|
||||
<label string="If you unreconciliate transactions, you must also verify all the actions that are linked to those transactions because they will not be disable" colspan="2"/>
|
||||
<separator colspan="4"/>
|
||||
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
|
||||
<button name="trans_unrec" default_focus="1" string="Unreconcile" type="object" icon="gtk-ok"/>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<act_window name="Unreconcile entries"
|
||||
res_model="account.voucher.unreconcile"
|
||||
src_model="account.voucher"
|
||||
view_mode="form"
|
||||
target="new"
|
||||
key2="client_action_multi"
|
||||
id="action_view_account_voucher_unreconcile"/>
|
||||
</record>
|
||||
<record model="ir.actions.act_window" id="action_view_account_voucher_unreconcile">
|
||||
<field name="name">Unreconcile entries</field>
|
||||
<field name="res_model">account.voucher.unreconcile</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="view_account_voucher_unreconcile"/>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<!-- <act_window name="Unreconcile entries" -->
|
||||
<!-- res_model="account.voucher.unreconcile"-->
|
||||
<!-- src_model="account.voucher"-->
|
||||
<!-- view_mode="form"-->
|
||||
<!-- target="new" -->
|
||||
<!-- key2="client_action_multi" -->
|
||||
<!-- id="action_view_account_voucher_unreconcile"/>-->
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
</openerp>
|
||||
|
||||
Reference in New Issue
Block a user