Ashvin Rathod (OpenERP) has proposed merging
lp:~openerp-dev/openobject-addons/account_voucher_rework_ara into
lp:~openerp/openobject-addons/trunk-account-voucher-rework-qdp.
Requested reviews:
OpenERP Core Team (openerp)
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/account_voucher_rework_ara/+merge/70418
Hello,
- Improved find method of Period as per
lp:~openerp-dev/openobject-addons/6.0-opw-5852-pso branch.
- company_id field of account.voucher to be a fields.related (journal_id,
company_id)
- onchange of journal, set the company_id and the period_id fields.
Thanks,
ara
--
https://code.launchpad.net/~openerp-dev/openobject-addons/account_voucher_rework_ara/+merge/70418
Your team OpenERP R&D Team is subscribed to branch
lp:~openerp-dev/openobject-addons/account_voucher_rework_ara.
=== modified file 'account/account.py'
--- account/account.py 2011-07-15 12:44:33 +0000
+++ account/account.py 2011-08-04 10:11:23 +0000
@@ -918,10 +918,17 @@
return False
def find(self, cr, uid, dt=None, context=None):
+ if context is None: context = {}
if not dt:
dt = time.strftime('%Y-%m-%d')
#CHECKME: shouldn't we check the state of the period?
- ids = self.search(cr, uid, [('date_start','<=',dt),('date_stop','>=',dt)])
+ args = [('date_start', '<=' ,dt), ('date_stop', '>=', dt)]
+ if context.get('company_id', False):
+ args.append(('company_id', '=', context['company_id']))
+ else:
+ company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id
+ args.append(('company_id', '=', company_id))
+ ids = self.search(cr, uid, args, context=context)
if not ids:
raise osv.except_osv(_('Error !'), _('No period defined for this date: %s !\nPlease create one.')%dt)
return ids
=== modified file 'account_voucher/account_voucher.py'
--- account_voucher/account_voucher.py 2011-07-15 14:41:26 +0000
+++ account_voucher/account_voucher.py 2011-08-04 10:11:23 +0000
@@ -39,7 +39,10 @@
if context is None: context = {}
if context.get('period_id', False):
return context.get('period_id')
- periods = self.pool.get('account.period').find(cr, uid)
+ if context.get('invoice_id', False):
+ company_id = self.pool.get('account.invoice').browse(cr, uid, context['invoice_id'], context=context).company_id.id
+ context.update({'company_id': company_id})
+ periods = self.pool.get('account.period').find(cr, uid, context=context)
return periods and periods[0] or False
def _get_journal(self, cr, uid, context=None):
@@ -152,11 +155,11 @@
for l in line_dr_ids:
real_amount -= l.get('amount_in_company_currency', 0.0)
counter_for_writeoff -= currency_pool.compute(cr, uid, l['company_currency_id'], l['voucher_currency_id'], l.get('amount_in_company_currency',0.0), context=ctx)
- counter_for_currency_diff -= currency_pool.compute(cr, uid, l['currency_id'], l['company_currency_id'], l['amount'], context=ctx)
+ counter_for_currency_diff -= currency_pool.compute(cr, uid, l['currency_id'], l['company_currency_id'], l['amount'], context=ctx)
for l in line_cr_ids:
real_amount += l.get('amount_in_company_currency', 0.0)
counter_for_writeoff += currency_pool.compute(cr, uid, l['company_currency_id'], l['voucher_currency_id'], l.get('amount_in_company_currency',0.0), context=ctx)
- counter_for_currency_diff += currency_pool.compute(cr, uid, l['currency_id'], l['company_currency_id'], l['amount'], context=ctx)
+ counter_for_currency_diff += currency_pool.compute(cr, uid, l['currency_id'], l['company_currency_id'], l['amount'], context=ctx)
writeoff_amount = amount - counter_for_writeoff
currency_rate_difference = real_amount - counter_for_currency_diff
return writeoff_amount, currency_rate_difference
@@ -167,7 +170,7 @@
line_osv = self.pool.get("account.voucher.line")
line_dr_ids = resolve_o2m_operations(cr, uid, line_osv, line_dr_ids, ['amount'], context)
line_cr_ids = resolve_o2m_operations(cr, uid, line_osv, line_cr_ids, ['amount'], context)
- writeoff_amount, currency_rate_diff = self._compute_writeoff_amount(cr, uid, line_dr_ids, line_cr_ids, amount, voucher_date, context=context)
+ writeoff_amount, currency_rate_diff = self._compute_writeoff_amount(cr, uid, line_dr_ids, line_cr_ids, amount, voucher_date, context=context)
return {'value': {'writeoff_amount': writeoff_amount,}}# 'currency_rate_difference': currency_rate_diff}}
def _get_writeoff_amount(self, cr, uid, ids, name, args, context=None):
@@ -185,15 +188,15 @@
counter_for_writeoff -= (l.voucher_currency_id.id == l.company_currency_id.id) and l.amount_in_company_currency or l.amount_in_voucher_currency
#ctx.update({'date': l.date_original})
#counter_for_writeoff -= currency_pool.compute(cr, uid, voucher.company_id.currency_id.id, voucher.currency_id.id, l.amount_in_company_currency, context=ctx)
- counter_for_currency_diff -= currency_pool.compute(cr, uid, l.currency_id.id, voucher.company_id.currency_id.id, l.amount, context=ctx)
+ counter_for_currency_diff -= currency_pool.compute(cr, uid, l.currency_id.id, voucher.company_id.currency_id.id, l.amount, context=ctx)
for l in voucher.line_cr_ids:
real_amount += l.amount_in_company_currency
counter_for_writeoff += (l.voucher_currency_id.id == l.company_currency_id.id) and l.amount_in_company_currency or l.amount_in_voucher_currency
#ctx.update({'date': l.date_original})
#counter_for_writeoff += currency_pool.compute(cr, uid, voucher.company_id.currency_id.id, voucher.currency_id.id, l.amount_in_company_currency, context=ctx)
- counter_for_currency_diff += currency_pool.compute(cr, uid, l.currency_id.id, voucher.company_id.currency_id.id, l.amount, context=ctx)
+ counter_for_currency_diff += currency_pool.compute(cr, uid, l.currency_id.id, voucher.company_id.currency_id.id, l.amount, context=ctx)
writeoff_amount = voucher.amount - counter_for_writeoff
- res[voucher.id]['writeoff_amount'] = writeoff_amount
+ res[voucher.id]['writeoff_amount'] = writeoff_amount
res[voucher.id]['currency_rate_difference'] = real_amount - counter_for_currency_diff
return res
@@ -228,7 +231,7 @@
'currency_id': fields.function(_currency_id, type='many2one', relation='res.currency', string='Currency', store=True, readonly=True, multi="currency"),
#duplicated field for display purposes
'currency_id2': fields.function(_currency_id, type='many2one', relation='res.currency', string='Currency', store=True, readonly=True, multi="currency"),
- 'company_id': fields.many2one('res.company', 'Company', required=True, readonly=True, states={'draft':[('readonly',False)]}),
+ 'company_id': fields.related('journal_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, readonly=True),
'company_currency': fields.related('company_id','currency_id', type='many2one', relation='res.currency', string='Currency', readonly=True),
'state':fields.selection(
[('draft','Draft'),
@@ -545,9 +548,9 @@
'move_line_id':line.id,
'account_id':line.account_id.id,
'amount_original': amount_original,
- 'amount': (move_line_found == line.id) and min(price, amount_unreconciled) or 0.0,
+ 'amount': (move_line_found == line.id) and min(price, amount_unreconciled) or 0.0,
'currency_id': currency_id,
- 'voucher_currency_id': voucher_currency_id,
+ 'voucher_currency_id': voucher_currency_id,
'date_original':line.date,
'company_currency_id': line.company_id.currency_id.id,
'date_due':line.date_maturity,
@@ -596,9 +599,13 @@
@param context: context arguments, like lang, time zone
@return: Returns a dict which contains new values, and context
"""
+ if context is None: context = {}
period_pool = self.pool.get('account.period')
res = self.onchange_partner_id(cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, date, context=context)
- pids = period_pool.search(cr, uid, [('date_start', '<=', date), ('date_stop', '>=', date)])
+ if context.get('invoice_id', False):
+ company_id = self.pool.get('account.invoice').browse(cr, uid, context['invoice_id'], context=context).company_id.id
+ context.update({'company_id': company_id})
+ pids = period_pool.find(cr, uid, date, context=context)
if pids:
if not 'value' in res:
res['value'] = {}
@@ -606,6 +613,7 @@
return res
def onchange_journal(self, cr, uid, ids, journal_id, line_ids, tax_id, partner_id, context=None):
+ if context is None: context = {}
if not journal_id:
return {}
journal_pool = self.pool.get('account.journal')
@@ -621,6 +629,9 @@
if journal.currency:
currency_id = journal.currency.id
vals['value'].update({'currency_id':currency_id})
+ context.update({'company_id': journal.company_id.id})
+ periods = self.pool.get('account.period').find(cr, uid, context=context)
+ vals['value'].update({'period_id':periods[0]})
return vals
def proforma_voucher(self, cr, uid, ids, context=None):
@@ -766,7 +777,7 @@
account_id = voucher.company_id.property_income_currency_exchange
if not account_id:
raise osv.except_osv(_('Warning'),_("Unable to create accounting entry for currency rate difference. You have to configure the field 'Expense Currency Rate' on the company! "))
-
+
currency_diff_line = {
'name': _('Currency Difference'),
'debit': voucher.currency_rate_difference > 0 and voucher.currency_rate_difference or 0.0,
@@ -833,7 +844,7 @@
if not currency_pool.is_zero(cr, uid, voucher.currency_id, voucher.writeoff_amount):
#create one line for the write off if needed
- diff = currency_pool.compute(cr, uid, voucher_currency, company_currency, voucher.writeoff_amount, context=context_multi_currency)
+ diff = currency_pool.compute(cr, uid, voucher_currency, company_currency, voucher.writeoff_amount, context=context_multi_currency)
account_id = False
write_off_name = ''
if voucher.payment_option == 'with_writeoff':
@@ -939,7 +950,7 @@
def _get_amount_in_company_currency(self, cr, uid, ids, name, args, context=None):
res = {}
for line in self.browse(cr, uid, ids, context=context):
- amount_in_company_currency, amount_in_voucher_currency = self.__company_currency_amount(cr, uid, line, line.amount, context=context)
+ amount_in_company_currency, amount_in_voucher_currency = self.__company_currency_amount(cr, uid, line, line.amount, context=context)
res[line.id] = {
'amount_in_company_currency': amount_in_company_currency,
'amount_in_voucher_currency': amount_in_voucher_currency,
@@ -948,7 +959,7 @@
_columns = {
'voucher_id':fields.many2one('account.voucher', 'Voucher', required=1, ondelete='cascade'),
- 'move_line_id': fields.many2one('account.move.line', 'Journal Item', required=True),
+ 'move_line_id': fields.many2one('account.move.line', 'Journal Item'),
'type':fields.selection([('dr','Debit'),('cr','Credit')], 'Dr/Cr'),
'name':fields.char('Description', size=256),
'account_id':fields.many2one('account.account','Account', required=True),
@@ -961,8 +972,8 @@
'voucher_currency_id': fields.related('voucher_id', 'currency_id', type='many2one', relation='res.currency', string="Voucher Currency"),
'amount':fields.float('Amount', digits_compute=dp.get_precision('Account')),
- 'amount_in_company_currency': fields.function(_get_amount_in_company_currency, string='Amount in Company Currency', type='float', digits_compute=dp.get_precision('Account'), multi="voucher_line_amount"),
- 'amount_in_voucher_currency': fields.function(_get_amount_in_company_currency, string='Amount in Voucher Currency', type='float', digits_compute=dp.get_precision('Account'), multi="voucher_line_amount"),
+ 'amount_in_company_currency': fields.function(_get_amount_in_company_currency, string='Amount in Company Currency', type='float', digits_compute=dp.get_precision('Account'), multi="voucher_line_amount"),
+ 'amount_in_voucher_currency': fields.function(_get_amount_in_company_currency, string='Amount in Voucher Currency', type='float', digits_compute=dp.get_precision('Account'), multi="voucher_line_amount"),
'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),
=== modified file 'account_voucher/voucher_payment_receipt_view.xml'
--- account_voucher/voucher_payment_receipt_view.xml 2011-07-15 12:47:38 +0000
+++ account_voucher/voucher_payment_receipt_view.xml 2011-08-04 10:11:23 +0000
@@ -108,7 +108,7 @@
<page string="Payment Information">
<field name="line_dr_ids" attrs="{'invisible': [('type', '=', 'receipt')]}" default_get="{'journal_id':journal_id, 'type':type, 'partner_id':partner_id}" colspan="4" nolabel="1" height="140" on_change="onchange_line_ids(line_dr_ids, line_cr_ids, amount)">
<tree string="Open Supplier Journal Entries" editable="bottom">
- <field name="move_line_id" context="{'journal_id':parent.journal_id, 'partner_id':parent.partner_id}"
+ <field name="move_line_id" required="1" context="{'journal_id':parent.journal_id, 'partner_id':parent.partner_id}"
on_change="onchange_move_line_id(move_line_id)"
domain="[('account_id.type','=','payable'), ('reconcile_id','=', False), ('partner_id','=',parent.partner_id)]"
/>
@@ -122,7 +122,7 @@
</field>
<field name="line_cr_ids" colspan="4" nolabel="1" attrs="{'invisible': [('type', '=', 'payment')]}" default_get="{'journal_id':journal_id, 'partner_id':partner_id}" on_change="onchange_line_ids(line_dr_ids, line_cr_ids, amount)">
<tree string="Open Customer Journal Entries" editable="bottom">
- <field name="move_line_id"/>
+ <field name="move_line_id" required="1"/>
<field name="account_id" groups="base.group_extended" domain="[('type','=','receivable')]"/>
<field name="date_original"/>
<field name="amount_original"/>
@@ -173,7 +173,7 @@
<page string="Payment Information">
<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="Supplier Invoices and Outstanding transactions" editable="bottom">
- <field name="move_line_id" context="{'journal_id':parent.journal_id, 'partner_id':parent.partner_id}"
+ <field name="move_line_id" required="1" context="{'journal_id':parent.journal_id, 'partner_id':parent.partner_id}"
on_change="onchange_move_line_id(move_line_id)"
domain="[('account_id.type','=','payable'), ('reconcile_id','=', False), ('partner_id','=',parent.partner_id)]"
/>
@@ -187,7 +187,7 @@
</field>
<field name="line_cr_ids" colspan="4" nolabel="1" attrs="{'invisible': [('pre_line','=',False)]}" default_get="{'journal_id':journal_id, 'partner_id':partner_id}">
<tree string="Credits" editable="bottom">
- <field name="move_line_id"/>
+ <field name="move_line_id" required="1"/>
<field name="account_id" groups="base.group_extended" domain="[('type','=','receivable')]"/>
<field name="date_original"/>
<field name="amount_original"/>
@@ -306,7 +306,7 @@
<field name="reference" colspan="4" select="1" invisible="context.get('line_type', False)" string="Payment Ref"/>
<field name="name" colspan="4" invisible="context.get('line_type', False)"/>
<field name="company_id" colspan="4" widget="selection" groups="base.group_multi_company"/>
- <field name="account_id" colspan="4"
+ <field name="account_id" colspan="4"
widget="selection"
invisible="True"/>
<field name="pre_line" colspan="4" invisible="1"/>
@@ -316,7 +316,7 @@
<page string="Payment Information">
<field name="line_cr_ids" default_get="{'journal_id':journal_id, 'type':type, 'partner_id':partner_id}" colspan="4" nolabel="1" height="140" on_change="onchange_line_ids(line_dr_ids, line_cr_ids, amount, date)">
<tree string="Invoices and outstanding transactions" editable="bottom">
- <field name="move_line_id" context="{'journal_id':parent.journal_id, 'partner_id':parent.partner_id}"
+ <field name="move_line_id" required="1" context="{'journal_id':parent.journal_id, 'partner_id':parent.partner_id}"
on_change="onchange_move_line_id(move_line_id)"
domain="[('account_id.type','in',('receivable','payable')), ('reconcile_id','=', False), ('partner_id','=',parent.partner_id)]"
/>
@@ -335,7 +335,7 @@
</field>
<field name="line_dr_ids" colspan="4" nolabel="1" attrs="{'invisible': [('pre_line','=',False)]}" default_get="{'journal_id':journal_id, 'partner_id':partner_id}" on_change="onchange_line_ids(line_dr_ids, line_cr_ids, amount, date)">
<tree string="Credits" editable="bottom">
- <field name="move_line_id" context="{'journal_id':parent.journal_id, 'partner_id':parent.partner_id}"
+ <field name="move_line_id" required="1" context="{'journal_id':parent.journal_id, 'partner_id':parent.partner_id}"
on_change="onchange_move_line_id(move_line_id)"
domain="[('account_id.type','in',('receivable','payable')), ('reconcile_id','=', False), ('partner_id','=',parent.partner_id)]"
/>
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp