OPENERP 销售invoice(无税) 源码分析
-
接上贴 点击SO003的 创建发票 按钮
[attach]477[/attach]
[attach]478[/attach]
[attach]479[/attach][attach]480[/attach]
[attach]481[/attach]
[attach]482[/attach]
[attach]483[/attach]
[attach]484[/attach]
[attach]497[/attach]
更确切的说是 1 计算发票的付款到期日 2 生成会计凭证 3 更新 发票/会计凭证/会计分录 的编号 4 更改发票的状态为 OPEN
这里面的第一个 方法
def action_date_assign(self, cr, uid, ids, *args):
for inv in self.browse(cr, uid, ids):
res = self.onchange_payment_term_date_invoice(cr, uid, inv.id, inv.payment_term.id, inv.date_invoice)
if res and res['value']:
self.write(cr, uid, [inv.id], res['value'])
return True
作用就是计算付款到期日,根据付款规则计算付款到期日这里面的第二个方法 是这里的核心方法 放在最后说明
这里面的第三个方法
def action_number(self, cr, uid, ids, *args):
cr.execute('SELECT id, type, number, move_id, reference '
'FROM account_invoice '
'WHERE id IN ('+','.join(map(str,ids))+')')
obj_inv = self.browse(cr, uid, ids)[0]
for (id, invtype, number, move_id, reference) in cr.fetchall():
if not number:
if obj_inv.journal_id.invoice_sequence_id:
sid = obj_inv.journal_id.invoice_sequence_id.id
number = self.pool.get('ir.sequence').get_id(cr, uid, sid, 'id=%s', {'fiscalyear_id': obj_inv.period_id.fiscalyear_id.id})
else:
number = self.pool.get('ir.sequence').get(cr, uid,
'account.invoice.' + invtype)
if invtype in ('in_invoice', 'in_refund'):
ref = reference
else:
ref = self._convert_ref(cr, uid, number)
cr.execute('UPDATE account_invoice SET number=%s '
'WHERE id=%s', (number, id))
cr.execute('UPDATE account_move SET ref=%s '
'WHERE id=%s AND (ref is null OR ref = '')',
(ref, move_id))
cr.execute('UPDATE account_move_line SET ref=%s '
'WHERE move_id=%s AND (ref is null OR ref = '')',
(ref, move_id))
cr.execute('UPDATE account_analytic_line SET ref=%s '
'FROM account_move_line '
'WHERE account_move_line.move_id = %s '
'AND account_analytic_line.move_id = account_move_line.id',
(ref, move_id))
return True
更新 发票/会计凭证/会计分录 的编号在介绍第二个方法时 先说明一下它用到的一些方法
[attach]498[/attach][attach]499[/attach]
现在到终于到第三个方法了
[attach]500[/attach]
[attach]501[/attach]
[attach]502[/attach]
[attach]503[/attach]
[attach]504[/attach][color=Red] total[/color] += i['price'] [color=Magenta]i['price'] = - i['price'][/color] 和 iml.append({ 'type': 'dest', 'name': name, '[color=Magenta]price[/color]'[color=Red]: total,[/color] 'account_id': acc_id, 'date_maturity' : inv.date_due or False, 'amount_currency': diff_currency_p and total_currency or False, 'currency_id': diff_currency_p and inv.currency_id.id or False, 'ref': ref }) 这个就是 影响 debit 和 credit 'debit':x['[color=Magenta]price[/color]']>0 and x['[color=Magenta]price[/color]'], 'credit':x['[color=Magenta]price[/color]']<0 and -x['[color=Magenta]price[/color]'],
菜终于上来了 可以开动了 点击 创建 发票的按钮
[attach]505[/attach]
11[[i] 本帖最后由 leetaizhu 于 2010-3-31 15:20 编辑 [/i]]