第一次用代码 创建 产品 遇挫
-
第一次用代码 创建 产品,失败了
现象是 OE 拼起来的SQL 中 缺少了一个关键字段少了name 字段:
2013-01-31 08:54:06,545 7400 ERROR t72 openerp.sql_db: Programming error: can't adapt type 'instancemethod', in query insert into "product_template" (id,"supply_method","uos_id","list_price","description","standard_price","mes_type","uom_id","categ_id","cost_method","name","uos_coeff","volume","sale_delay","procure_method","sale_ok","purchase_ok","company_id","produce_delay","uom_po_id","rental","type",create_uid,create_date,write_uid,write_date) values (3261,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,(now() at time zone 'UTC'),%s,(now() at time zone 'UTC'))
2013-01-31 08:54:10,292 7400 ERROR t72 openerp.osv.osv: Uncaught exception
mrshelly 帮指了路,先减少字段,
果然,减少到只有几个 字段后,
create 就OK 了<br /><br /> ## 下一步,创建一个 模版 制品,需要的参数从该 模版产品 中复制<br /> vals = {<br /> 'name': 'gsgcp' , #+ mmold.stand_name<br /> # 'description': 'auto create', # 队<br /> # 'type': 'product', # 产品类型 <br /> # 'active': True, # 生效<br /> 'categ_id': categ_id,<br /> # 'list_price': 120.8,<br /> # 'standard_price': 99.8,<br /> 'volume': mmold.m3_per_ctn, # 成品的体积是 箱立方<br /> <br /> # 'uom_id': self._get_uom_id, # 单位<br /> # 'uom_po_id': self._get_uom_id,<br /> # 'uos_id': self._get_uom_id,<br /> <br /> # 'seller_ids': uid , # 销售员<br /> # 'sale_ok':True, # 可以销售<br /> # 'default_code': 'gcp-' + mmold.gsgcode ,<br /> <br /> }<br /> <br /> # vals['default_code'] = 'gcp-' + mmold.gsgcode # 另外一种赋值的方法<br /> <br /> # 用 vals 中指定的数据, 创建一个 产品 <br /> new_id = product_obj.create(cr, uid, vals, context=context)<br /> <br />
另外还有些 稀奇的错误
UnboundLocalError: local variable 'bool_fields' referenced before assignment
经总监mrshelly 指出,问题在<br />'sale_ok': True, 不正雀...<br />
必须是<br />1 ok<br /><br />0 ok<br />false ok<br />False ok<br />off ok<br />超出这些, 就not ok<br /><br />