我是OpenERP的新手。我在ubuntu 12.04 LTS和eclipse SDK上开发了一个新模块安装在OpenERP v7中,但是我得到了以下错误。
验证字段arch时出现“ValidateError错误:View Architecture的XML无效!”
请有人可以帮助我吗?
以下是我的文件。
_init.py
from . import mrp_extend
_ OpenERP的 _。PY
{
'name' : 'MRP Extend',
'version' : '1.0',
'author' : 'Sydney Cake House',
'website' : 'www.makcik.com',
'category' : 'MRP Extend',
'description' : ''' This module provides functionality for OpenERP extended mrp purpose,
''',
'depends' : ['mrp'],
'data' : ['view/mrp_extend.xml'],
'auto_install' : False,
'installable' : True,
'demo' : [],
'test' : []
}
mrp_extend.py
import time
from datetime import datetime
import openerp.addons.decimal_precision as dp
from openerp.osv import fields, osv, orm
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT, DATETIME_FORMATS_MAP
from openerp.tools import float_compare
from openerp.tools.translate import _
from openerp import netsvc
from openerp import tools
from openerp import SUPERUSER_ID
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
def _get_default_uom(self, cr, uid, context=None):
uom_ids = self.pool.get('product.uom').search(cr, uid, [('name','=','PCE')], context=context)
if not uom_ids:
raise osv.except_osv(_('Error!'), _('There is no default UOM!'))
return uom_ids[0]
_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="Total Product Unit Cost", digits_compute=dp.get_precision('Product Price')),
'total_cost' : fields.function(get_total_cost, string="Total Cost", digits_compute=dp.get_precision('Product Price')),
'production_unit_quantity' : fields.float('Production Unit Quantity', required=True, digits_compute=dp.get_precision('Product Unit of Measure')),
'product_unit_uom': fields.many2one('product.uom', 'Product Unit of Measure', required=True, help="Unit of Measure (Unit of Measure) is the unit of measurement for the inventory control"),
'mrp_bom_ids' : fields.one2many('mrp.extend.bom', 'mrp_extend_id', 'MRP Extend', states={'done': [('readonly', False)]})
}
_defaults = {
'total_cost': lambda *a: 0.0,
'production_unit_quantity': lambda *a: 0.0,
'product_unit_uom': _get_default_uom,
}
def onchange_product_id(self, cr, uid, ids, product_id, name, context=None):
""" Changes UoM and name if product_id changes.
@param name: Name of the field
@param product_id: Changed product_id
@return: Dictionary of changed values
"""
if product_id:
prod = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
return {'value': {'name': prod.name, 'product_uom': prod.uom_id.id, 'product_unit_cost': prod.standard_price}}
return {}
def onchange_uom(self, cr, uid, ids, product_id, product_uom, context=None):
res = {'value':{}}
if not product_uom or not product_id:
return res
product = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
uom = self.pool.get('product.uom').browse(cr, uid, product_uom, context=context)
if uom.category_id.id != product.uom_id.category_id.id:
res['warning'] = {'title': _('Warning'), 'message': _('The Product Unit of Measure you chose has a different category than in the product form.')}
res['value'].update({'product_uom': product.uom_id.id})
return res
class mrp_production_extend(osv.Model):
_inherit = 'mrp.production'
def _get_total_cost(self, cr, uid, ids, field_name, arg, context):
res = {}
for bom_point in self.browse(cr, uid, ids, context=context):
res[bom_point.id] = bom_point.bom_id.total_cost or 0.00
return res
def _get_product_qty(self, cr, uid, ids, field_name, arg, context):
res = {}
for bom_point in self.browse(cr, uid, ids, context=context):
res[bom_point.id] = bom_point.bom_id.product_qty or 0.00
return res
def _get_production_unit_qty(self, cr, uid, ids, field_name, arg, context):
res = {}
for bom_point in self.browse(cr, uid, ids, context=context):
res[bom_point.id] = bom_point.bom_id.production_unit_quantity or 0.00
return res
def _get_final_total_cost(self, cr, uid, ids, field_name, arg, context):
res = {}
for bom_point in self.browse(cr, uid, ids, context=context):
if bom_point.bom_id.product_qty > 1:
res[bom_point.id] = ((bom_point.bom_id.total_cost or 0.00) / (bom_point.bom_id.product_qty or 0.00) * bom_point.product_qty)
else:
res[bom_point.id] = (bom_point.bom_id.total_cost or 0.00) * bom_point.product_qty
return res
_columns = {
'production_unit_quantity' : fields.function(_get_production_unit_qty, string="Product Unit Quantity", digits_compute=dp.get_precision('Product Unit of Measure')),
'total_cost' : fields.function(_get_total_cost, string="Total Cost", digits_compute=dp.get_precision('Product Price')),
'pre_set_qty' : fields.function(_get_product_qty, string="Pre Set Quantity", digits_compute=dp.get_precision('Product Unit of Measure')),
'total_final_cost' : fields.function(_get_final_total_cost, string="Total Final Cost", digits_compute=dp.get_precision('Product Price')),
'mrp_production_ids' : fields.one2many('mrp.production.extend.bom', 'mrp_production_extend_id', 'MRP Production Extend', states={'done': [('readonly', False)]})
}
mrp_extend.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Add new field MRP Extend in Bill Of Materials (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">form</field-->
<field name="inherit_id" ref="mrp.mrp_bom_form_view" />
<field name="arch" type="xml">
<group >
<group colspan="4" col="4">
<field name="total_cost" string="Total Cost" invisible="True"/>
<label for="production_unit_quantity" string="Production Unit Quantity"/>
<div>
<field name="production_unit_quantity" class="oe_inline"/>
<field name="product_unit_uom" class="oe_inline" groups="product.group_uom"/>
</div>
</group>
</group>
</field>
</record>
<!-- Add new field MRP Extend in Bill Of Materials (By Henry on 07/Nov/2013) -->
<record id="stock_ext_tree" model="ir.ui.view">
<field name="name">mrp.ext.tree</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" widget="one2many_list">
<tree string="Components" editable="bottom">
<field name="product_id" context="{'default_supply_method':'produce'}" on_change="onchange_product_id(product_id, name)"/>
<field name="product_qty"/>
<field name="product_uom" on_change="onchange_uom(product_id, product_uom)" groups="product.group_uom"/>
<field name="product_unit_cost"/>
<field name="product_total_cost" sum="Total Product Unit Cost"/>
<field name="name" invisible="1"/>
<field name="date_start"/>
<field name="date_stop"/>
</tree>
</field>
</field>
</record>
<!-- Add new field for MRP Production Extend in Manufaturing Order (By Henry on 07/Nov/2013) -->
<record id="mrp_production_ext_form" model="ir.ui.view">
<field name="name">mrp.production.ext.form</field>
<field name="model">mrp.production</field>
<!-- <field name="type">form</field-->
<field name="inherit_id" ref="mrp.mrp_production_form_view" />
<field name="arch" type="xml">
<field name="origin" position="after">
<field name="total_cost" invisible="True"/>
<field name="pre_set_qty" invisible="True"/>
<field name="production_unit_quantity" invisible="False"/>
<field name="total_final_cost" invisible="False"/>
</field>
</field>
</record>
</data>
</openerp>