简体   繁体   English

odoo11模型中列条目的总和

[英]Sum of column entries in a model odoo11

I have a model as follows, 我有一个模型如下

class RecipeInformation(models.Model):
    _name = 'model.recipe.information'
    _description = 'recipe and ingredient information'

    recipe_id = fields.Many2one('model.recipe', string='Recipe', required=True)
    ingredient_id = fields.Many2one('model.ingredient', string='Ingredient', required=True)

    quantity = fields.Integer('Quantity', required=True, default=1)
    price = fields.Float('Price', required=True)
    unit_of_measure = fields.Selection([('milligrams', 'Milligrams'), ('grams', 'Grams'),('kilograms', 'Kilograms')],
                                   'Unit of Measure', default='grams',
                                   required=True)

    price_per_UoM = fields.Float('Price/UoM', compute='_calculate_price', store=True)

    Cost = fields.Float('Total Cost')

    @api.depends('price', 'quantity')
    def _calculate_price(self):
        for record in self:
            record.price_per_UoM = record.price / record.quantity
            return record.price_per_UoM

    @api.depends('ingredient_quantity', 'price_per_UoM')
    def _calculate_cost(self):
        for record in self:
            record.Cost += record.ingredient * record.price_per_UoM
            return record.Cost

and an xml tree and form view as follows 以及xml树和表单视图,如下所示

<record id="view_form_recipe_cost" model="ir.ui.view">
        <field name="name">recipe.cost.form.view</field>
        <field name="model">model.recipe.information</field>
        <field name="arch"  type="xml">
            <form string="Recipe Cost form view">
                <sheet>
                    <group>
                        <field name="recipe_id"/>
                        <field name="ingredient_id"/>
                        <field name="quantity"/>
                        <field name="price"/>
                        <field name="unit_of_measure"/>
                        <field name="price_per_UoM"/>
                    </group>
                </sheet>
            </form>
         </field>
    </record>
    <record id="view_tree_recipe_cost" model="ir.ui.view">
        <field name="name">recipe.cost.tree.view</field>
        <field name="model">model.recipe.information</field>
        <field name="arch"  type="xml">
            <tree>
                <field name="recipe_id"/>
                <field name="ingredient_id"/>
                <field name="quantity"/>
                <field name="price"/>
                <field name="unit_of_measure"/>
                <field name="price_per_UoM"/>
            </tree>
         </field>
    </record>

What I am trying to do is get the sum of all the price_perUoM for each row entry in my model that has the same recipe name or recipe_id and view them possibly in another split view. 我想做的是获取模型中具有相同配方名称或recipe_id每个行条目的所有price_perUoM的总和,并可能在另一个拆分视图中查看它们。

so that I can have a tree view displaying all the fields and another displaying only the recipe name and total cost of that particular recipe 这样我就可以在树视图中显示所有字段,在另一个视图中仅显示该特定配方的配方名称和总成本

I am new to odoo and I would appreciate any (advice, comments) help. 我是odoo的新手,我将感谢您的任何(建议,意见)帮助。

thanks in advance 提前致谢

有一个属性名称sum =“ Total”,您可以将其应用于xml树视图,该视图显示针对特定列显示的所有记录的总和

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM