我的继承函数有一些错误

时间:2019-07-02 10:23:56

标签: python xml inheritance odoo-11

我在odoo中的继承存在错误

  

odoo.tools.convert.ParseError:“验证约束字段生产日期不存在错误

我已经附上了XML代码和python文件

我也尝试过更改文件名并将模型保存在单独的文件中

XML文件

<odoo>
  <data>
    <record id="stock_form_inherite_view" model="ir.ui.view">
      <field name="name">stock.date.inherit.view</field>
      <field name="model">stock.picking</field>
      <field name="inherit_id" ref="stock.view_picking_form" />
      <field name="arch" type="xml">
        <xpath expr="//field[@name='move_line_ids']/tree/field[@name='product_id']" position="after">
          <field name='production_date' readonly="1"/>
          <field name='expiry_date' readonly="1"/>
        </xpath>
      </field>
    </record>
  </data>
</odoo>

Python文件

from odoo import models, fields

class StockPicking(models.Model):
"""Added the new field quantity which is related field to   stock_move."""
_inherit = 'stock.picking'

product_qty = fields.Float(string="Quantity", related="move_lines.product_uom_qty")



class stockpickingline(models.Model):
"""Added For the Production Date and Expiry Date"""
_inherit='account.invoice.line'
lot_number = fields.Many2one('stock.production.lot', string='Lot Number')
production_date = fields.Date('Production date',  related='lot_number.production_date')
expiry_date = fields.Datetime('Expiry date', related='lot_number.life_date')

1 个答案:

答案 0 :(得分:0)

您要在py的account.invoice.line中添加production_date字段,并在stock_picking的move_line_ids中调用它。通常,stock.picking中的move_line_ids与stock_move模型有关。请检查move_line_ids关系。