0

这是我要扩展现有的 mrp.bom 的新创建的 mrp_extend.py 文件:

class mrp_extend(osv.Model):

    _inherit = 'mrp.bom'

    def _get_unit_cost(self, cr, uid, ids, field_name, arg, context):
        result = {}

        for bom_line_obj in self.browse(cr, uid, ids, context=context):
            result[bom_line_obj.id] = bom_line_obj.product_id.product_tmpl_id.standard_price or 0.00
        return result 

    def _get_product_total_cost(self, cr, uid, ids, field_name, arg, context):
        result = {}

        for bom_line_obj in self.browse(cr, uid, ids, context=context):
            result[bom_line_obj.id] = (bom_line_obj.product_id.product_tmpl_id.standard_price or 0.00) * (bom_line_obj.product_qty or 0.00)
        return result 

    def get_total_cost(self, cr, uid, ids, name, args, context=None):
        res = {}
        for rec in self.browse(cr, uid, ids, context=context):
            total_cost = 0.0
            for line_rec in rec.bom_lines:
                total_cost += line_rec.product_total_cost or 0.0
            res.update({rec.id : total_cost})
        return res

    _columns = {
        'product_unit_cost' : fields.function(_get_unit_cost, string="Product Unit Cost", digits_compute=dp.get_precision('Product Price')),
        'product_total_cost' : fields.function(_get_product_total_cost, string="Product Unit Cost", digits_compute=dp.get_precision('Product Price')),
        'total_cost' : fields.function(get_total_cost, string="Total Cost"),
        'mrp_bom_ids' : fields.one2many('mrp.extend.bom', 'mrp_extend_id', 'Stock Extend Log', states={'done': [('readonly', False)]})
    }

我创建了新的 mrp_extend.xml:

<?xml version="1.0" encoding="utf-8"?>

<openerp>
    <data>
        <!-- Add new field in MRP (By Henry on 07/Nov/2013) -->
        <record id="stock_ext_form" model="ir.ui.view">
            <field name="name">mrp.ext.form</field>
            <field name="model">mrp.bom</field>
            <field name="type">tree</field>
            <field name="inherit_id" ref="mrp.mrp_bom_form_view" />
            <field name="arch" type="xml">
                <field name="bom_lines" position="after">
                    <field name="product_unit_cost"/>
                    <field name="product_total_cost" sum="Total Product Unit Cost"/> 
                </field>                                     
            </field>
        </record>   
    </data>
</openerp>

我现在的问题是,如何在 mrp.bom 中存在的 bom_lines 树字段中显示我新创建的字段?

请帮忙。

4

1 回答 1

0

您可以使用相关字段。请参考OpenERP 相关字段

于 2013-11-08T05:42:41.410 回答