0

数量のデフォルト値を M.sqr に保存し、デフォルトの入力値を示す手持数量のような平方メートルを保存する必要があります。

製品在庫ページから手持ち数量の更新ボタンをクリックすると、以前に入力した値が表示されます。

class stock_change_product_qty(osv.osv):

_inherit = 'stock.change.product.qty'
_columns = {
    'new_quantity' : fields.float('Qty in Boxes'),
    'squ_meter': fields.related('product_id','squ_meter', type='float', relation='product.product', string='Square Meter'),
    'qty_char': fields.float('Qty in M.sqr', compute='_compute_qty_char'),

}

@api.depends('new_quantity', 'squ_meter')
def _compute_qty_char(self):
    for record in self:
        record.qty_char = record.new_quantity * record.squ_meter

view.xml

        <field name="name">update_product_quantity inherit</field>
        <field name="model">stock.change.product.qty</field>
        <field name="inherit_id" ref="stock.view_change_product_quantity"/>
        <field name="arch" type="xml">

            <xpath expr="//field[@name='new_quantity']"  position="attributes">
                <attribute name="string">Qty in Boxes</attribute>
            </xpath>
    <xpath expr="//field[@name='new_quantity']"  position="replace">

                <field name="new_quantity"/>
                <field name="squ_meter"/>
                <field name="qty_char"/>

            </xpath>
        </field>
    </record>
4

1 に答える 1

0

解決策は、フィールドのデフォルト値として関数を使用することです。

おどーV8

from openerp import api, fields, models

class stock_change_product_qty(models.Model):

    _inherit = 'stock.change.product.qty'

     new_quantity = fields.Float(string='Qty in Boxes', default=1.0),
     squ_meter = fields.Float(related='product_id.squ_meter', string='Square Meter', default=1.0),
     qty_char = fields.Float('Qty in M.sqr', compute='_compute_qty_char'),

      }

    @api.one
    @api.depends('new_quantity', 'squ_meter')
    def _compute_qty_char(self):
        for record in self:
            record.qty_char = record.new_quantity * record.squ_meter

おどーV7

def _your_function(self, cr, uid, context=None):
    your code here
    ...
    ...
    ...
    return field_value

_defaults = {
    'your_field' : _your_function,
    }

@api.onchange

このデコレーターは、デコレーターで指定されたフィールドのいずれかが次の形式で変更された場合に、装飾された関数の呼び出しをトリガーします。

@api.onchange('fieldx')
def do_stuff(self):
    if self.fieldx == x:
        self.fieldy = 'toto'

前のサンプルの self は、フォームで現在編集されているレコードに対応します。on_change コンテキストでは、すべての作業がキャッシュで行われます。したがって、データベースの変更を心配することなく、関数内で RecordSet を変更できます。それが @api.depends との主な違いです

関数が戻るときに、キャッシュと RecordSet の違いがフォームに返されます。

于 2015-12-24T06:04:15.350 に答える