gpt4 book ai didi

python - openerp 服务器操作 - python 代码

转载 作者:行者123 更新时间:2023-11-28 18:52:44 25 4
gpt4 key购买 nike

我不知道我是否应该在这里问这个问题(我现在想也许版主会把它移到 stackoverflow),但我在 openerp 或 launchpad 论坛上没有得到答案。
在 OpenERP 6.0.1 中,当在发票表单中放置一个按钮以执行它时,以下函数将执行它应该执行的操作:

class account_invoice(osv.osv):
_inherit = "account.invoice"

""" Function to update all lines on invoice """
def update_invoice(self, cr, uid, ids, context=None):
if context is None:
context = {}
line_obj = self.pool.get('account.invoice.line')
invoice_ids = self.browse(cr, uid, ids, context)
for invoice in invoice_ids:
for line in invoice.invoice_line:
if line.product_id:
res = line_obj.product_id_change(cr, uid, [line.id], (line.product_id and line.product_id.id or False), uom=(line.uos_id and line.uos_id.id or False), qty=(line.quantity or 0),
name=(line.name or ''), type=(invoice.type or False), partner_id=invoice.partner_id.id, fposition_id=invoice.fiscal_position.id, price_unit=(line.price_unit or 0),
address_invoice_id=(invoice.address_invoice_id and invoice.address_invoice_id.id or False), currency_id=(invoice.currency_id and invoice.currency_id.id or False), context=context)
price_unit = res['value']['price_unit']
discount = res['value']['discount']
line_obj.write(cr, uid, [line.id], {'price_unit': price_unit})
line_obj.write(cr, uid, [line.id], {'discount': discount})
return True

account_invoice()

也就是说,当在表单中单击此按钮时,发票行的价格单位和折扣会更新。

我正在尝试为“python 代码”类型的对象“发票”创建服务器操作,该操作对菜单项中的所有发票执行此功能。在 python 代码框中,我写道:

inv = self.pool.get('account.invoice')
line_obj = self.pool.get('account.invoice.line')
for invoice in inv.browse(cr, uid, ids):
for line in invoice.invoice_line:
res = line_obj.product_id_change(cr, uid, [line.id], (line.product_id and line.product_id.id or False), uom=(line.uos_id and line.uos_id.id or False), qty=(line.quantity or 0), name=(line.name or ''), type=(invoice.type or False), partner_id=invoice.partner_id.id, fposition_id=invoice.fiscal_position.id, price_unit=(line.price_unit or 0), address_invoice_id=(invoice.address_invoice_id and invoice.address_invoice_id.id or False), currency_id=(invoice.currency_id and invoice.currency_id.id or False), context=context)
price_unit = res['value']['price_unit']
discount = res['value']['discount']
line_obj.write(cr, uid, [line.id], {'price_unit': price_unit})
line_obj.write(cr, uid, [line.id], {'discount': discount})

但它不起作用。我做错了什么?

编辑:谁能帮我写一个函数来更新所有发票行,类似于/account/wizard/account_invoice_state.py 中的行?

最佳答案

如果我想在屏幕中选定的行上运行一些代码,我使用带有 client_action_multi 的向导。这是 a wizard I wrote这只是在选股上设置了一个“健全性检查”标志:

import wizard
import pooler

def _set_flags(self, cr, uid, data, context):
stock_picking_obj = pooler.get_pool(cr.dbname).get('stock.picking')

move_ids = data['ids']
picking_ids = stock_picking_obj.search(
cr,
uid,
[('move_lines', 'in', move_ids)])
stock_picking_obj.write(cr, uid, picking_ids, {'sanity_checked': True})
return {}

class sanity_checked(wizard.interface):
states = {
'init': {
'actions': [_set_flags],
'result': {'type': 'state', 'state':'end'}
},
}
sanity_checked('promise.date.sanity.checked')

configure the wizard使用 client_action_multi 以便它可以在列表中的选定记录上执行:

<wizard
id="wiz_sanity_checked"
model="stock.move"
string="Sanity Checked"
name="promise.date.sanity.checked"
keyword="client_action_multi"/>

要实际运行向导,请单击菜单栏中的“操作”按钮。

关于python - openerp 服务器操作 - python 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9771165/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com