首页 文章

如何将默认计算应用于list_price字段产品odoo v11 [关闭]

提问于
浏览
-1

来自odoo导入模型,字段,api

class product_template(models.Model):

_inherit = 'product.template'
  remise = fields.float('remise du fournisseur', size=10, required=True)
  marge = fields.float('marge', size=10, required=True)
  total_reste = fields.float('Reste', size=10, required=True)

def onchange_calculer(val1, val2):
    return {'value': {'list_price': val1 * (val2/100) + val1}}

}

<我的xml视图文件代码

<record id="view_product_form" model="ir.ui.view">

        <field name="name">product.template.common.form</field>

        <field name="model">product.template</field>

        <field name="inherit_id" ref="product.product_template_form_view"/>

        <field name="arch" type="xml">

    <xpath expr="//field[@name='list_price']" position="after">

        <field name="x_remise1"/>

        <field name="x_marge1"/>

        <field name="list_price"

on_change =“onchange_calculer(standard_price,x_marge1)”readonly =“True”/>

</xpath>

        </field>

    </record>

我不明白为什么它不起作用

3 回答

  • 1

    试试吧 .

    @api.multi
    @api.onchange('val1','val2')
    def onchange_calculer(self):
        for s in self:
            s.list_price = s.val1 * (s.val2/100) + s.val1
    

    其中val1和val2是product.template对象的字段,onchage_calculer将在检测到val1和val2字段值的任何更改时启动 . 对不起我的英语不好 .

    P.D:fields.float('')sintax在v11中运行?

  • 0

    在视图中:

    <field name="name">product.template.common.form</field>
    
        <field name="model">product.template</field>
    
        <field name="inherit_id" ref="product.product_template_form_view"/>
    
        <field name="arch" type="xml">
    
            <xpath expr="//field[@name='list_price']" position="after">
                <field name="remise"/><!--this name is how u declared on model, no x_remise1-->
                <field name="marge"/><!--this name is how u declared on model, no x_marge1-->
                <field name="example_field" />
            </xpath>
        </field>
    </record>
    

    在班上

    class ProductTemplate(models.Model)
    _inherit = 'product.template'
    
    remise = fields.Float('remise du fournisseur', size=10, required=True)
    marge = fields.Float('marge', size=10, required=True)
    total_reste = fields.Float('Reste', size=10, required=True)
    example_field = fields.Float('example')
    
    @api.multi
    @api.onchange('standard_price','marge')
    def onchange_calculer(self):
        for s in self:
            s.example_field = s.standard_price * (s.marge/100) + s.standard_price
    

    如果在模型中没有定义,为什么你在wiew上使用x_marge1和x_remise1?

  • 0

    别忘了:

    --your_module/
        --__init__.py -> import models
        --manifest.py
        --models/
              --_init__.py ->import porduct_template
              --product_template.py
        --views/
    

相关问题