0
我在修改採購模塊以在採購訂單行中添加新字段。我已成功添加代碼以創建模型並查看自定義字段。但無法將自定義字段添加到P.O.的總量中。線。自定義OpenERP模塊不能按預期工作
class customPo(osv.osv):
_inherit="purchase.order"
#_name = 'customPo'
def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
res = {}
cur_obj=self.pool.get('res.currency')
for order in self.browse(cr, uid, ids, context=context):
res[order.id] = {
'amount_untaxed': 0.0,
'amount_tax': 0.0,
'amount_total': 0.0,
}
val = val1 = 0.0
cur = order.pricelist_id.currency_id
for line in order.order_line:
# val1 += line.price_subtotal
val1 = val1 + line.data + line.price_subtotal
for c in self.pool.get('account.tax').compute_all(cr, uid, line.taxes_id, line.price_unit, line.product_qty, line.product_id, order.partner_id)['taxes']:
val += c.get('amount', 0.0)
res[order.id]['amount_tax']=cur_obj.round(cr, uid, cur, 42.0)
res[order.id]['amount_untaxed']=cur_obj.round(cr, uid, cur, val1)
res[order.id]['amount_total']=res[order.id]['amount_untaxed'] + res[order.id]['amount_tax']
return res
_columns = {
'order_line': fields.one2many('purchase.order.line', 'order_id', 'Order Lines', states={'approved':[('readonly',True)],'done':[('readonly',True)]}),
'amount_untaxed': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Untaxed Amount',
store={
'purchase.order.line': (_get_order, None, 10),
}, multi="sums", help="The amount without tax", track_visibility='always'),
'amount_tax': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Taxes',
store={
'purchase.order.line': (_get_order, None, 10),
}, multi="sums", help="The tax amount"),
'amount_total': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Total',
store={
'purchase.order.line': (_get_order, None, 10),
}, multi="sums",help="The total amount"),
}
customPo()
class customPol(osv.osv):
_inherit = 'purchase.order.line'
# _name = 'something.notpurchase'
_columns = {
'data': fields.float('Unit Price', required=True, digits_compute= dp.get_precision('Product Price')),
}
customPol()
我已經將稅收靜態保留爲42,所以我可以知道什麼時候重寫的方法被調用,但它從來沒有發生過。
我的觀點文件如下。
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="custom_purchse_wa" model="ir.ui.view">
<field name="name">Custom Field New</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<xpath expr="/form/sheet/notebook/page/field[@name='order_line']/tree/field[@name='price_unit']" position="after">
<field name="data" string="Custom field"/>
</xpath>
</field>
</record>
</data>
</openerp>
計算可以看到的視野?如果是的話,你可以爲字段數據指定任何浮點變量嗎?請檢查數據庫是否輸入數據庫 – OmaL
>可以查看字段,可以添加數據,數據拷貝到數據庫,可以通過修改purchase.py(內置模塊)將數據添加到我的總數中但是我的challange(標準程序)是在沒有修改原始購買的情況下做同樣的事情.py –
@AshokKumarSahoo您能否成功在採購訂單中添加此值,並且每個計算工作都可以像稅收那樣工作,如果是,請將總數加上 –