Hello,
I have a custom model that have a relation One2many with stock.move, here's my code :
class CpsProductTemplate(models.Model): _name = 'cps.product.template' reference = fields.Char(string="Référence") reception_line_ids= fields.One2many("stock.move", 'product_template_reception_id', string="Liste des récéptions", domain= '[("to_refund", "=", False)]') date_reception = fields.Datetime(related='reception_line_ids.date_expected', string="Date de reception") total_reception_one2many = fields.Integer(compute="_compute_total_reception_one2many", string="Entrées") @api.depends('date_reception') def _compute_total_reception_one2many(self): for p in self: totalentree = 0 for entree in self.with_context().reception_line_ids.filtered(lambda t: t.product_id.id == p.product_id.id): if entree.picking_id.origin is False: totalentree+=entree.product_uom_qty p.total_reception_dynamique =totalentree
My xml tree
<record model="ir.ui.view" id="cps_product_production_tree_view"> <field name="name">cps.product.production.tree</field> <field name="model">cps.product.production</field> <field name="arch" type="xml"> <tree string="Commande production"> <field name="reference"/> <field name="total_reception_one2many"/> </tree> </field> </record>My goal is to have the sum of the field "total_reception_one2many" according to what the user have filtered in "date_reception". Is there any way to get the filter applied by the user in the search area on the tree? Thanks in advance
Check odoo Tips: https://www.scoop.it/t/learn-openerp