类型错误:generate_purchase_order() 只需要 1 个参数(给定 5 个)
Posted
技术标签:
【中文标题】类型错误:generate_purchase_order() 只需要 1 个参数(给定 5 个)【英文标题】:TypeError: generate_purchase_order() takes exactly 1 argument (5 given) 【发布时间】:2016-07-12 06:14:05 【问题描述】:我正在尝试将 openerp 7 代码转换为 odoo8。在 V7 中,browse() 方法有几个参数,例如 self、cr、uid、ids、context,但在 V8 中,我认为这些都不需要。在我的自定义模块中,我试图根据从 mrp 获得的信息创建采购订单。我已经对要制造 10000 本书需要多少公斤纸进行了自定义计算。计算后,此信息应转到采购发票。产品将从材料清单中获得,数量从所需纸张的公斤数和来自产品成本属性的单价。我无法解决此错误“方法只需要 1 个参数(给定 5 个)”
mrp.py,
from openerp import models
class mrp_production(models.Model):
_inherit = 'mrp.production'
def generate_purchase_order(self,supplier_id,warehouse_id):
purchase_obj = self.env['purchase.order']
purchase_line_obj = self.env['purchase.order.line']
warehouse_obj = self.env['stock.warehouse']
warehouse = warehouse_obj.browse(warehouse_id)
if not warehouse:
return False
if isinstance(warehouse, list):
warehouse = warehouse[0]
for order in self:
vals =
vals = purchase_obj.onchange_partner_id()
vals['origin'] = order.name
vals['partner_id'] = supplier_id
vals['warehouse_id'] = warehouse_id
vals['location_id'] = warehouse.lot_stock_id.id
vals['date_order'] = order.date_planned
purchase_id = purchase_obj.create(vals)
for line in self.bom_id.bom_line_ids:
if not line.product_id:
continue
line_vals = purchase_line_obj.onchange_product_id(line.product_id.id,
line.product_uom_qty, line.product_uom.id, supplier_id,
date_planned=line.date_planned)['value']
line_vals['name'] = line.name
line_vals['product_id'] = line.product_id.id
if not line_vals.get('price_unit', False):
line_vals['price_unit'] = line.product_id.list_price
line_vals['product_uom'] = line.product_uom.id
line_vals['product_uom_qty'] = 181.13
line_vals['order_id'] = purchase_id
purchase_line_obj.create(line_vals)
return True
generate_purchase_order.py,
from openerp import models,fields,api
class generate_purchase_order(models.Model):
_name = 'mrp_to_purchase_order.generate_purchase_order'
_description = 'Generate Purchase Order'
partner_id = fields.Many2one('res.partner', 'Supplier', required=True, domain="[('supplier','=',True)]")
warehouse_id = fields.Many2one('stock.warehouse', 'Warehouse', required=True)
@api.multi
def onchange_partner_id(self,partner_id):
return
def generate_purchase_order(self):
for wizard in self:
#mrp_order_ids = [context['active_id']]
mrp_obj = self.env['mrp.production']
mrp_obj.generate_purchase_order(wizard.partner_id.id, wizard.warehouse_id.id)
return 'type': 'ir.actions.act_window_close'
【问题讨论】:
【参考方案1】:如果您从模型中的某个其他方法调用generate_purchase_order
方法,则为该方法使用装饰器@api.multi
。
同样在你的generate_purchase_order
方法中,替换
for order in self.browse():
由
for order in self:
编辑
@api.multi
def generate_purchase_order(self):
for wizard in self:
#mrp_order_ids = [context['active_id']]
mrp_obj = self.env['mrp.production']
# Get the mrp record
mrp_rec = code to get mrp record
mrp_rec.generate_purchase_order(wizard.partner_id.id, wizard.warehouse_id.id)
return 'type': 'ir.actions.act_window_close'
【讨论】:
generate_purchase_order 方法被另一个类调用 在你的代码中更新那个方法,这样我就可以检查你的“generate_purchase_order”中的哪一行导致了错误? browse() 问题已解决,但我现在收到此错误:TypeError: generate_purchase_order() 只需要 1 个参数(给定 5 个) 我在第一个文件而不是第二个文件中从 mrp 获取信息。在第二个文件中,我只是发送合作伙伴和仓库的 ID。以上是关于类型错误:generate_purchase_order() 只需要 1 个参数(给定 5 个)的主要内容,如果未能解决你的问题,请参考以下文章
Flutter fromJson - 未处理的错误未处理的错误类型'String'不是'int'类型的子类型发生在实例中
我在尝试登录或注册时收到错误消息“错误类型‘AuthResult’不是类型转换中‘FirebaseUser’类型的子类型”