if not context:
context={}
ids = []
-
if name:
- ids += self.search(cr, user, [('name','=',name)], limit=limit)
- if not ids:
- ids += self.search(cr, user, [('id','=',name)], limit=limit)
+ ids += self.search(cr, user, [('name','ilike',name)]+args, limit=limit, context=context)
+
+ if not ids and name and type(name) == int:
+ ids += self.search(cr, user, [('id','=',name)]+args, limit=limit, context=context)
+ if not ids:
+ ids += self.search(cr, user, args, limit=limit, context=context)
+
return self.name_get(cr, user, ids, context=context)
def name_get(self, cursor, user, ids, context=None):
##############################################################################
import time
+import netsvc
from osv import fields
from osv import osv
from tools.translate import _
_name = 'account.voucher'
_description = 'Accounting Voucher'
_order = "id desc"
+ _rec_name = 'number'
+
_columns = {
- 'name':fields.char('Name', size=256, required=True, readonly=True, states={'draft':[('readonly',False)]}),
+ 'name':fields.char('Name', size=256, required=False, readonly=True, states={'draft':[('readonly',False)]}),
'type': fields.selection([
('payment', 'Payment'),
('receipt', 'Receipt'),
'journal_id':_get_journal,
'currency_id': _get_currency,
'state': lambda *a: 'draft',
+ 'name': lambda *a: '/',
'date' : lambda *a: time.strftime('%Y-%m-%d'),
'reference_type': lambda *a: "none",
'audit': lambda *a: False,
})
new_line += [tax_line]
-
if new_line:
for line in new_line:
voucher_line_pool.create(dbcr, uid, line)
'state':voucher.state
}
self.write(dbcr, uid, ids, res)
- else:
- raise osv.except_osv(_('Invalid amount !'), _('You can not create Pro-Forma voucher with Total amount <= 0 !'))
+
return True
- def write(self, cr, uid, ids, vals, context={}):
- res = super(account_voucher, self).write(cr, uid, ids, vals, context)
-
- #If there is state says that method called from the work flow signals
- if not 'state' in vals.keys():
- self.open_voucher(cr, uid, ids, context)
-
- return res
+# def write(self, cr, uid, ids, vals, context={}):
+# res = super(account_voucher, self).write(cr, uid, ids, vals, context)
+#
+# #If there is state says that method called from the work flow signals
+# if not 'state' in vals.keys():
+# self.open_voucher(cr, uid, ids, context)
+#
+# return res
def voucher_recheck(self, cr, uid, ids, context={}):
- #self.open_voucher(cr, uid, ids, context)
+# self.open_voucher(cr, uid, ids, context)
self.write(cr, uid, ids, {'state':'recheck'}, context)
return True
def proforma_voucher(self, cr, uid, ids, context={}):
- #self.open_voucher(cr, uid, ids, context)
+# self.open_voucher(cr, uid, ids, context)
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, context={}):
+ wf_service = netsvc.LocalService("workflow")
+ for voucher_id in ids:
+ wf_service.trg_create(uid, 'account.voucher', voucher_id, cr)
self.write(cr, uid, ids, {'state':'draft'})
return True
def audit_pass(self, cr, uid, ids, context={}):
move_pool = self.pool.get('account.move')
+
result = True
audit_pass = []
for voucher in self.browse(cr, uid, ids):
if inv.move_id:
continue
+ if not inv.payment_ids:
+ raise osv.except_osv(_('Error !'), _('Please define lines on voucher !'))
+
journal = journal_pool.browse(cr, uid, inv.journal_id.id)
if journal.sequence_id:
name = sequence_pool.get_id(cr, uid, journal.sequence_id.id)
rec = {
'move_id': move_id,
- 'move_ids':[(6, 0,line_ids)]
}
-
+
message = _('Voucher ') + " '" + inv.name + "' "+ _("is confirmed")
self.log(cr, uid, inv.id, message)
self.write(cr, uid, [inv.id], rec)
-
+ move_pool.post(cr, uid, [move_id], context={})
+
return True
def _convert_ref(self, cr, uid, ref):
'voucher_id':fields.many2one('account.voucher', 'Voucher'),
'name':fields.char('Memo', size=256, required=True),
'account_id':fields.many2one('account.account','Account', required=True, domain=[('type','<>','view')]),
- 'partner_id': fields.many2one('res.partner', 'Partner', change_default=True),
+# 'partner_id': fields.many2one('res.partner', 'Partner', change_default=True),
+ 'partner_id': fields.related('voucher_id','partner_id', type='many2one', relation='res.partner', string='Partner'),
'amount':fields.float('Amount'),
'type':fields.selection([('dr','Debit'),('cr','Credit')], 'Type'),
'ref':fields.char('Reference', size=32),
elif ttype == 'cr' and type1 in ('purchase'):
account_id = partner.property_account_payable.id
- else:
- raise osv.except_osv(_('Invalid Configuration !'), _('You can not encode unbalanced entry !'))
-
if company.currency_id != currency:
balance = currency_pool.compute(cr, uid, company.currency_id.id, currency, balance)
<field name="date"/>
<field name="number"/>
<field name="reference"/>
- <field name="name"/>
+ <field name="partner_id"/>
<field name="journal_id"/>
<field name="type" invisible=" not context.get('set_visible',True)"/>
- <field name="account_id" />
+ <field name="account_id"/>
<field name="amount" sum="Total Amount"/>
<field name="period_id"/>
<field name="state"/>
+ <button name="proforma_voucher" string="Create" states="draft" icon="terp-document-new"/>
+ <button name="recheck_voucher" string="Approve" states="recheck" icon="terp-check"/>
+ <button name="action_cancel_draft" type="object" states="cancel" string="Set to Draft" icon="terp-stock_effects-object-colorize"/>
</tree>
</field>
</record>
<field name="arch" type="xml">
<form string="Accounting Voucher">
<group col="6" colspan="4">
- <field name="name" colspan="4"/>
+ <field name="partner_id"/>
+ <field name="name"/>
<field name="number"/>
<field name="journal_id" select="1" on_change="onchange_journal(journal_id,type)"/>
<field name="account_id" on_change="onchange_account(account_id)"/>
<field name="type" on_change="onchange_journal(journal_id,type)"/>
</group>
+
<notebook colspan="4">
<page string="Voucher Entry">
<field name="payment_ids" colspan="4" nolabel="1" height="180">
<tree string="Voucher Lines" editable="top">
- <field name="partner_id" on_change="onchange_partner(partner_id,type,parent.type, parent.currency_id)"/>
+ <field name="name" on_change="onchange_partner(parent.partner_id,type,parent.type, parent.currency_id)"/>
<field name="account_id"/>
- <field name="name"/>
- <field name="type" on_change="onchange_type(partner_id,type,parent.type, parent.currency_id)"/>
+ <field name="type" on_change="onchange_type(parent.partner_id,type,parent.type, parent.currency_id)"/>
<field name="amount"/>
- <field name="account_analytic_id"/>
<field name="ref"/>
+ <field name="account_analytic_id"/>
</tree>
</field>
<group col="2" colspan="3">
<separator string="Other Information" colspan="2"/>
<field name="reference" select="1"/>
<field name="date" select="1" on_change="onchange_date(date)"/>
- <field name="currency_id" select="1"/>
+ <field name="currency_id" select="1" attrs="{'readonly':[('type','in',['sale', 'purchase'])]}"/>
</group>
</page>
<page string="Journal Items">
<button name="recheck_voucher" string="Approve" states="recheck" icon="terp-check"/>
<!-- <button name="audit_complete" string="Audit Pass" states="posted" icon="terp-check"/>-->
<button name="cancel_voucher" string="Cancel" states="draft,proforma,recheck" icon="gtk-cancel"/>
- <button name="cancel_to_draft" states="cancel" string="Set to Draft" icon="terp-stock_effects-object-colorize"/>
+ <button name="action_cancel_draft" type="object" states="cancel" string="Set to Draft" icon="terp-stock_effects-object-colorize"/>
</group>
</form>
</field>
</group>
<newline/>
<group expand="0" string="Group By..." col='8' colspan='4'>
+ <filter string="Partner" icon="terp-partner" domain="[]" context="{'group_by':'partner_id'}"/>
<filter string="Journal" icon="terp-folder-orange" domain="[]" context="{'group_by':'journal_id'}"/>
<filter string="Period" icon="terp-go-month" domain="[]" context="{'group_by':'period_id'}"/>
<filter string="Type" icon="terp-stock_symbol-selection" domain="[]" context="{'group_by':'type', 'set_visible':True}"/>
</group>
<newline/>
<group expand="0" string="Group By..." colspan="12" col="10">
+ <filter string="Partner" icon="terp-partner" domain="[]" context="{'group_by':'partner_id'}"/>
<filter string="Journal" icon="terp-folder-orange" domain="[]" context="{'group_by':'journal_id'}"/>
<filter string="Period" icon="terp-go-month" domain="[]" context="{'group_by':'period_id'}"/>
<filter string="Type" icon="terp-stock_symbol-selection" domain="[]" context="{'group_by':'type', 'set_visible':True}"/>
<record id="act_cancel" model="workflow.activity">
<field name="wkf_id" ref="wkf"/>
<field name="name">cancel</field>
+ <field name="flow_stop">True</field>
<field name="action">cancel_voucher()</field>
<field name="kind">function</field>
</record>
from osv import fields, osv
from tools.translate import _
-class account_invoice(osv.osv):
- _inherit = 'account.invoice'
-
+class account_move(osv.osv):
+ _inherit = 'account.move'
+
def search(self, cr, user, args, offset=0, limit=None, order=None, context=None, count=False):
"""
Returns a list of ids based on search domain {args}
if not context:
context = {}
ttype = context.get('ttype', False)
+ partner = context.get('partner_id', False)
+ voucher = context.get('voucher', False)
+ if voucher and not partner:
+ raise osv.except_osv(_('Invalid Partner !'), _('Please select the partner !'))
+
if ttype and ttype in ('receipt'):
- args += [('type','in', ['out_invoice', 'in_refund'])]
+ args += [('journal_id.type','in', ['sale', 'purchase_refund'])]
elif ttype and ttype in ('payment'):
- args += [('type','in', ['in_invoice', 'out_refund'])]
+ args += [('journal_id.type','in', ['purchase', 'sale_refund'])]
elif ttype and ttype in('sale', 'purchase'):
raise osv.except_osv(_('Invalid action !'), _('You can not reconcile sales, purchase, or journal voucher with invoice !'))
- args += [('type','=', 'do_not_allow_search')]
-
- res = super(account_invoice, self).search(cr, user, args, offset, limit, order, context, count)
+ args += [('journal_id.type','=', 'do_not_allow_search')]
+ res = super(account_move, self).search(cr, user, args, offset, limit, order, context, count)
return res
-account_invoice()
+account_move()
class account_move_line(osv.osv):
_inherit = "account.move.line"
class account_voucher(osv.osv):
_inherit = 'account.voucher'
_columns = {
- 'voucher_line_ids':fields.one2many('account.voucher.line', 'voucher_id', 'Voucher Lines', readonly=False, states={'proforma':[('readonly',True)]}),
+ 'voucher_line_ids':fields.one2many('account.voucher.line', 'voucher_id', 'Voucher Lines', readonly=True, states={'draft':[('readonly',False)]}),
}
def action_move_line_create(self, cr, uid, ids, *args):
if inv.move_id:
continue
-
+
+ if not inv.payment_ids:
+ raise osv.except_osv(_('Error !'), _('Please define lines on voucher !'))
+
journal = journal_pool.browse(cr, uid, inv.journal_id.id)
if journal.sequence_id:
name = sequence_pool.get_id(cr, uid, journal.sequence_id.id)
'move_id':move_id ,
'journal_id':inv.journal_id.id,
'period_id':inv.period_id.id,
- 'partner_id':False,
+ 'partner_id':inv.partner_id.id,
'ref':ref,
'date':inv.date
}
move_line_id = move_line_pool.create(cr, uid, move_line)
line_ids += [move_line_id]
- if line.invoice_id and inv.type in ('payment', 'receipt'):
+ if line.move_id and inv.type in ('payment', 'receipt'):
rec_ids += [move_line_id]
- for move_line in line.invoice_id.move_id.line_id:
+ for move_line in line.move_id.line_id:
if line.account_id.id == move_line.account_id.id:
rec_ids += [move_line.id]
move_line_pool.reconcile_partial(cr, uid, rec_ids)
rec = {
- 'move_id': move_id,
+ 'move_id': move_id
}
message = _('Voucher ') + " '" + inv.name + "' "+ _("is confirm")
self.log(cr, uid, inv.id, message)
self.write(cr, uid, [inv.id], rec)
+ move_pool.post(cr, uid, [move_id], context={})
- return True
+ return True
account_voucher()
return data
_columns = {
- 'invoice_id' : fields.many2one('account.invoice','Invoice'),
+# 'invoice_id' : fields.many2one('account.invoice','Invoice'),
+ 'move_id' : fields.many2one('account.move','Journal Entry'),
}
def move_line_get_item(self, cr, uid, line, context={}):
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')
+ invoice_pool = self.pool.get('account.move')
res = {
- 'amount':0.0
+
}
if not invoice_id:
return {
}
else:
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)
+ residual = invoice.amount
+
+ company_currency = self.pool.get('res.users').browse(cr, uid, uid).company_id.currency_id.id
+ currency_diff = company_currency != currency_id
- res.update({
- 'amount': residual,
- 'account_id': invoice.account_id.id,
- 'ref':invoice.number
- })
+ if currency_diff:
+ residual = currency_pool.compute(cr, uid, company_currency, currency_id, residual)
+
+ if residual > 0:
+ res.update({
+ 'amount': residual,
+ 'ref':invoice.name
+ })
return {
'value':res
<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="200">
+ <field name="voucher_line_ids" colspan="4" nolabel="1" height="200">
<tree string="Voucher Lines" editable="top">
- <field name="partner_id" on_change="onchange_partner(partner_id, type, parent.type, parent.currency_id)"/>
- <field name="account_id" on_change="onchange_line_account(account_id, type, parent.type)"/>
- <field name="name"/>
- <field name="invoice_id" context="{'ttype':parent.type}" on_change="onchange_invoice_id(invoice_id, parent.currency_id)" domain="[('partner_id','=',partner_id),('state','=','open'),('residual','>',0.0)]"/>
- <field name="type" on_change="onchange_type(partner_id,type,parent.type, parent.currency_id)"/>
+ <field name="name" on_change="onchange_partner(parent.partner_id,type,parent.type, parent.currency_id)"/>
+ <field name="account_id"/>
+ <field name="type" on_change="onchange_type(parent.partner_id,type,parent.type, parent.currency_id)"/>
+ <field name="move_id" context="{'ttype':parent.type, 'partner_id':parent.partner_id, 'voucher':True}" on_change="onchange_invoice_id(move_id, parent.currency_id)" domain="[('state','=','posted'), ('partner_id','=',parent.partner_id)]"/>
<field name="amount"/>
- <field name="account_analytic_id"/>
<field name="ref"/>
+ <field name="account_analytic_id"/>
</tree>
</field>
</field>
<field name="type">form</field>
<field name="inherit_id" ref="view_voucher_form"/>
<field name="arch" type="xml">
- <button name="cancel_to_draft" position="before">
+ <button name="action_cancel_draft" position="before">
<button name="%(action_view_account_voucher_unreconcile)d" string="Unreconcile" type="action" states="posted" icon="terp-stock_effects-object-colorize"/>
</button>
</field>
reconcile_pool.unlink(cr, uid, rec)
if res.remove:
- wf_service = netsvc.LocalService("workflow")
- wf_service.trg_validate(uid, 'account.voucher', context.get('active_id'), 'cancel_voucher', cr)
+ voucher_pool.cancel_voucher(cr, uid, [context.get('active_id')], context)
+# wf_service = netsvc.LocalService("workflow")
+# wf_service.trg_validate(uid, 'account.voucher', context.get('active_id'), 'cancel_voucher', cr)
return {}