[IMP]: improvement to the voucher module and some chanegs
bzr revid: mga@tinyerp.com-20100901161805-2o4trndpj9ufzr0m
This commit is contained in:
parent
983258cfff
commit
17cf2b6613
|
@ -1120,7 +1120,7 @@
|
|||
icon="STOCK_JUSTIFY_FILL"
|
||||
id="menu_action_account_moves_all"
|
||||
parent="account.menu_finance_entries"
|
||||
sequence="16"
|
||||
sequence="1"
|
||||
groups="group_account_user,group_account_manager,base.group_system"
|
||||
/>
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ class account_voucher(osv.osv):
|
|||
'tax_id':fields.many2one('account.tax', 'Tax', readonly=True, states={'draft':[('readonly',False)]}),
|
||||
'pre_line':fields.boolean('Previous Payments ?', required=False),
|
||||
'date_due': fields.date('Due Date'),
|
||||
'term_id':fields.many2one('account.payment.term', 'Term', required=False),
|
||||
# 'term_id':fields.many2one('account.payment.term', 'Term', required=False),
|
||||
}
|
||||
_defaults = {
|
||||
'period_id': _get_period,
|
||||
|
@ -280,10 +280,6 @@ class account_voucher(osv.osv):
|
|||
if journal.type in ('sale','sale_refund'):
|
||||
account_id = partner.property_account_receivable.id
|
||||
elif journal.type in ('purchase', 'purchase_refund','expense'):
|
||||
term_id = partner.property_payment_term.id
|
||||
if term_id:
|
||||
vals = self.onchange_term_id(cr, uid, ids, term_id, price)
|
||||
default['value'].update(vals.get('value'))
|
||||
account_id = partner.property_account_payable.id
|
||||
else:
|
||||
account_id = journal.default_credit_account_id.id or journal.default_debit_account_id.id
|
||||
|
@ -294,17 +290,20 @@ class account_voucher(osv.osv):
|
|||
if journal.type not in ('cash', 'bank'):
|
||||
return default
|
||||
|
||||
total_credit = 0.0
|
||||
total_debit = 0.0
|
||||
account_type = 'receivable'
|
||||
if ttype == 'payment':
|
||||
account_type = 'payable'
|
||||
total_debit = price or 0.0
|
||||
else:
|
||||
total_credit = price or 0.0
|
||||
account_type = 'receivable'
|
||||
|
||||
|
||||
ids = move_line_pool.search(cr, uid, [('account_id.type','=', account_type), ('reconcile_id','=', False), ('partner_id','=',partner_id)], context=context)
|
||||
ids.reverse()
|
||||
moves = move_line_pool.browse(cr, uid, ids)
|
||||
total_credit = price or 0.0
|
||||
total_debit = 0.0
|
||||
|
||||
for line in moves:
|
||||
if line.credit and line.reconcile_partial_id:
|
||||
continue
|
||||
|
@ -327,7 +326,7 @@ class account_voucher(osv.osv):
|
|||
rs['amount'] = min(line.amount_unreconciled, total_debit)
|
||||
total_debit -= rs['amount']
|
||||
else:
|
||||
rs['amount'] = min(line.debit, total_credit)
|
||||
rs['amount'] = min(line.amount_unreconciled, total_credit)
|
||||
total_credit -= rs['amount']
|
||||
|
||||
default['value']['line_ids'].append(rs)
|
||||
|
@ -384,9 +383,20 @@ class account_voucher(osv.osv):
|
|||
return True
|
||||
|
||||
def cancel_voucher(self, cr, uid, ids, context={}):
|
||||
reconcile_pool = self.pool.get('account.move.reconcile')
|
||||
move_pool = self.pool.get('account.move')
|
||||
voucher_line_pool = self.pool.get('account.voucher.line')
|
||||
|
||||
for voucher in self.browse(cr, uid, ids):
|
||||
recs = []
|
||||
for line in voucher.move_ids:
|
||||
if line.reconcile_id:
|
||||
recs += [line.reconcile_id.id]
|
||||
if line.reconcile_partial_id:
|
||||
recs += [line.reconcile_partial_id.id]
|
||||
|
||||
reconcile_pool.unlink(cr, uid, recs)
|
||||
|
||||
if voucher.move_id:
|
||||
move_pool.button_cancel(cr, uid, [voucher.move_id.id])
|
||||
move_pool.unlink(cr, uid, [voucher.move_id.id])
|
||||
|
@ -475,54 +485,47 @@ class account_voucher(osv.osv):
|
|||
if credit < 0:
|
||||
debit = -credit
|
||||
credit = 0.0
|
||||
if inv.type == 'purchase' and inv.term_id and _get_payment_term_lines(inv.term_id.id, credit or debit):
|
||||
terms = _get_payment_term_lines(inv.term_id.id, credit or debit)
|
||||
for term in terms:
|
||||
due_date = term[0]
|
||||
amount = term[1]
|
||||
move_line = {
|
||||
'name':inv.name or '/',
|
||||
'debit':0.0,
|
||||
'credit':amount,
|
||||
'date_maturity':due_date,
|
||||
'account_id':inv.account_id.id,
|
||||
'move_id':move_id ,
|
||||
'journal_id':inv.journal_id.id,
|
||||
'period_id':inv.period_id.id,
|
||||
'partner_id':inv.partner_id.id,
|
||||
'currency_id':inv.currency_id.id,
|
||||
'date':inv.date
|
||||
}
|
||||
master_line = move_line_pool.create(cr, uid, move_line)
|
||||
else:
|
||||
move_line = {
|
||||
'name':inv.name or '/',
|
||||
'debit':debit,
|
||||
'credit':credit,
|
||||
'account_id':inv.account_id.id,
|
||||
'move_id':move_id ,
|
||||
'journal_id':inv.journal_id.id,
|
||||
'period_id':inv.period_id.id,
|
||||
'partner_id':inv.partner_id.id,
|
||||
'currency_id':inv.currency_id.id,
|
||||
'date':inv.date
|
||||
}
|
||||
master_line = move_line_pool.create(cr, uid, move_line)
|
||||
|
||||
move_line = {
|
||||
'name':inv.name or '/',
|
||||
'debit':debit,
|
||||
'credit':credit,
|
||||
'account_id':inv.account_id.id,
|
||||
'move_id':move_id ,
|
||||
'journal_id':inv.journal_id.id,
|
||||
'period_id':inv.period_id.id,
|
||||
'partner_id':inv.partner_id.id,
|
||||
'currency_id':inv.currency_id.id,
|
||||
'date':inv.date,
|
||||
'date_maturity':inv.date_due
|
||||
}
|
||||
master_line = move_line_pool.create(cr, uid, move_line)
|
||||
|
||||
rec_list_ids = []
|
||||
line_total = debit - credit
|
||||
|
||||
if inv.type == 'sale':
|
||||
line_total = line_total - inv.tax_amount
|
||||
elif inv.type == 'purchase':
|
||||
line_total = line_total + inv.tax_amount
|
||||
|
||||
for line in inv.line_ids:
|
||||
if not line.amount:
|
||||
continue
|
||||
amount = currency_pool.compute(cr, uid, inv.currency_id.id, company_currency, line.amount)
|
||||
move_line = {
|
||||
'journal_id':inv.journal_id.id,
|
||||
'period_id':inv.period_id.id,
|
||||
'name':line.name and line.name or '/',
|
||||
'account_id':line.account_id.id,
|
||||
'move_id':move_id,
|
||||
'partner_id':inv.partner_id.id,
|
||||
'currency_id':inv.currency_id.id,
|
||||
'analytic_account_id':line.account_analytic_id and line.account_analytic_id.id or False,
|
||||
'quantity':1
|
||||
'quantity':1,
|
||||
'credit':0.0,
|
||||
'debit':0.0,
|
||||
'date':inv.date
|
||||
}
|
||||
if amount < 0:
|
||||
amount = -amount
|
||||
|
@ -530,7 +533,7 @@ class account_voucher(osv.osv):
|
|||
line.type = 'cr'
|
||||
else:
|
||||
line.type = 'dr'
|
||||
|
||||
|
||||
if (line.type=='dr'):
|
||||
line_total += amount
|
||||
move_line['debit'] = amount
|
||||
|
@ -538,43 +541,16 @@ class account_voucher(osv.osv):
|
|||
line_total -= amount
|
||||
move_line['credit'] = amount
|
||||
|
||||
if inv.tax_id:
|
||||
move_line.update({
|
||||
'account_tax_id':inv.tax_id.id,
|
||||
})
|
||||
|
||||
master_line = move_line_pool.create(cr, uid, move_line)
|
||||
if line.move_line_id.id:
|
||||
rec_ids = [master_line, line.move_line_id.id]
|
||||
rec_list_ids.append(rec_ids)
|
||||
|
||||
if inv.tax_amount:
|
||||
amount = currency_pool.compute(cr, uid, inv.currency_id.id, company_currency, inv.tax_amount)
|
||||
name = inv.tax_id and inv.tax_id.name or '/'
|
||||
move_line = {
|
||||
'name':name,
|
||||
'move_id':move_id ,
|
||||
'journal_id':inv.journal_id.id,
|
||||
'period_id':inv.period_id.id,
|
||||
'partner_id':inv.partner_id.id,
|
||||
'currency_id':inv.currency_id.id,
|
||||
}
|
||||
if inv.journal_id.type in ('sale','purchase_refund') and amount > 0:
|
||||
line_total -= amount
|
||||
move_line['credit'] = amount
|
||||
else:
|
||||
if amount < 0:
|
||||
amount = -amount
|
||||
line_total += amount
|
||||
move_line['debit'] = amount
|
||||
|
||||
account_id = False
|
||||
if inv.tax_id:
|
||||
if inv.journal_id.type in ('sale_refund','purchase_refund'):
|
||||
account_id = inv.tax_id.account_paid_id
|
||||
else:
|
||||
account_id = inv.tax_id.account_collected_id.id
|
||||
if not account_id:
|
||||
raise osv.except_osv(_('Invalid Error !'), _('No account defined on the related tax !'))
|
||||
move_line['account_id'] = account_id
|
||||
|
||||
move_line_id = move_line_pool.create(cr, uid, move_line)
|
||||
|
||||
if not self.pool.get('res.currency').is_zero(cr, uid, inv.currency_id, line_total):
|
||||
diff = line_total
|
||||
move_line = {
|
||||
|
@ -682,7 +658,7 @@ class account_voucher_line(osv.osv):
|
|||
'date_original': fields.related('move_line_id','date', type='date', relation='account.move.line', string='Date', readonly=1),
|
||||
'date_due': fields.related('move_line_id','date_maturity', type='date', relation='account.move.line', string='Due Date', readonly=1),
|
||||
'amount_original': fields.function(_compute_balance, method=True, type='float', string='Originial Amount', store=True),
|
||||
'amount_unreconciled': fields.related('move_line_id','amount_unreconciled', type='float', relation='account.move.line', string='Open Balance', readonly="1"),
|
||||
'amount_unreconciled': fields.related('move_line_id','amount_unreconciled', type='float', relation='account.move.line', string='Open Balance', store=True, readonly="1"),
|
||||
}
|
||||
_defaults = {
|
||||
'name': lambda *a: ''
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
widget="selection" select="1"
|
||||
on_change="onchange_partner_id(partner_id, journal_id, amount)"
|
||||
string="Payment Method"/>
|
||||
<field name="amount"/>
|
||||
<field name="amount" on_change="onchange_partner_id(partner_id, journal_id, amount, type)"/>
|
||||
<field name="reference" select="1" string="Payment Ref"/>
|
||||
<field name="name" colspan="4"/>
|
||||
<field name="account_id"
|
||||
|
@ -27,7 +27,7 @@
|
|||
</group>
|
||||
<notebook colspan="4">
|
||||
<page string="Payment Information">
|
||||
<field name="line_dr_ids" on_change="onchange_price(line_dr_ids, False, False)" default_get="{'journal_id':journal_id, 'type':type, 'partner_id':partner_id}" colspan="4" nolabel="1" height="140">
|
||||
<field name="line_dr_ids" default_get="{'journal_id':journal_id, 'type':type, 'partner_id':partner_id}" colspan="4" nolabel="1" height="140">
|
||||
<tree string="Payment Lines" editable="bottom">
|
||||
<field name="move_line_id" context="{'journal_id':parent.journal_id, 'partner_id':parent.partner_id}"
|
||||
on_change="onchange_move_line_id(move_line_id)"
|
||||
|
@ -77,9 +77,9 @@
|
|||
<group col="10" colspan="4">
|
||||
<field name="state"/>
|
||||
<button name="cancel_voucher" string="Cancel" states="draft,proforma" icon="gtk-cancel"/>
|
||||
<button name="cancel_voucher" string="Unreconcile" type="object" states="posted" icon="terp-stock_effects-object-colorize" confirm="Are you sure to unreconcile this record ?"/>
|
||||
<button name="proforma_voucher" string="Post" states="draft" icon="terp-camera_test"/>
|
||||
<button name="action_cancel_draft" type="object" states="cancel" string="Set to Draft" icon="terp-stock_effects-object-colorize"/>
|
||||
<button name="%(action_view_account_voucher_unreconcile)d" string="Unreconcile" type="action" states="posted" icon="terp-stock_effects-object-colorize"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
|
@ -171,9 +171,9 @@
|
|||
<group col="10" colspan="4">
|
||||
<field name="state"/>
|
||||
<button name="cancel_voucher" string="Cancel" states="draft,proforma" icon="gtk-cancel"/>
|
||||
<button name="cancel_voucher" string="Unreconcile" type="object" states="posted" icon="terp-stock_effects-object-colorize" confirm="Are you sure to unreconcile this record ?"/>
|
||||
<button name="proforma_voucher" string="Post" states="draft" icon="terp-camera_test"/>
|
||||
<button name="action_cancel_draft" type="object" states="cancel" string="Set to Draft" icon="terp-stock_effects-object-colorize"/>
|
||||
<button name="%(action_view_account_voucher_unreconcile)d" string="Unreconcile" type="action" states="posted" icon="terp-stock_effects-object-colorize"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
|
|
|
@ -4,12 +4,11 @@
|
|||
|
||||
<record id="act_pay_voucher" model="ir.actions.act_window">
|
||||
<field name="name">Sales Payment</field>
|
||||
<field name="res_model">account.voucher.open</field>
|
||||
<field name="res_model">account.voucher</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="domain">[('journal_id.type', 'in', ['bank', 'cash']), ('type','=','receipt'), ('partner_id','=',partner_id)]</field>
|
||||
<field name="context">{'journal_type':'bank', 'type':'receipt', 'partner_id': partner_id}</field>
|
||||
<field name="view_id" ref="account_open_vouchers_view"/>
|
||||
<field name="target">new</field>
|
||||
<field name="view_id" ref="view_vendor_payment_form"/>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="view_sale_receipt_form">
|
||||
<field name="name">account.voucher.sale.form</field>
|
||||
|
@ -71,10 +70,10 @@
|
|||
<group col="10" colspan="4">
|
||||
<field name="state"/>
|
||||
<button name="cancel_voucher" string="Cancel" states="draft,proforma" icon="gtk-cancel"/>
|
||||
<button name="cancel_voucher" string="Cancel" type="object" states="posted" icon="terp-stock_effects-object-colorize" confirm="Are you sure to confirm this record ?"/>
|
||||
<button name="proforma_voucher" string="Post" states="draft" icon="terp-camera_test"/>
|
||||
<button icon="terp-dolar_ok!" name="%(act_pay_voucher)d" context="{'title':'Sales Payment', 'journal_type':'bank', 'type':'receipt', 'partner_id': partner_id}" type="action" string="Pay" attrs="{'invisible':[('pay_now','!=','pay_now'),('state','!=','posted')]}"/>
|
||||
<button name="action_cancel_draft" type="object" states="cancel" string="Set to Draft" icon="terp-stock_effects-object-colorize"/>
|
||||
<button name="%(action_view_account_voucher_unreconcile)d" string="Cancel" type="action" states="posted" icon="terp-stock_effects-object-colorize"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
|
@ -126,7 +125,6 @@
|
|||
<group col="2" colspan="1">
|
||||
<group col="2" colspan="1">
|
||||
<separator string="Payment Terms" colspan="2"/>
|
||||
<field name="term_id" widget="selection" on_change="onchange_term_id(term_id, amount)"/>
|
||||
<field name="date" string="Bill Date" select="1" on_change="onchange_date(date)"/>
|
||||
<field name="date_due"/>
|
||||
<field name="amount" required="0" string="Amount Due"/>
|
||||
|
@ -151,9 +149,9 @@
|
|||
<group col="10" colspan="4">
|
||||
<field name="state"/>
|
||||
<button name="cancel_voucher" string="Cancel" states="draft,proforma" icon="gtk-cancel"/>
|
||||
<button name="cancel_voucher" string="Cancel" type="object" states="posted" icon="terp-stock_effects-object-colorize" confirm="Are you sure to confirm this record ?"/>
|
||||
<button name="proforma_voucher" string="Post" states="draft" icon="terp-camera_test"/>
|
||||
<button name="action_cancel_draft" type="object" states="cancel" string="Set to Draft" icon="terp-stock_effects-object-colorize"/>
|
||||
<button name="%(action_view_account_voucher_unreconcile)d" string="Cancel" type="action" states="posted" icon="terp-stock_effects-object-colorize"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
|
|
Loading…
Reference in New Issue