I am trying to make an automation in my model through code but I don't know if I am missing something because I add what I found on Google but at the end of a month it is not restored. I wish that through an accountant that I already have the method count the sales made in a month, that currently makes it but at the end of the month it continues adding the sales of the previous month and that I do not want, since the idea is that at the end of a month sales made in a month resume and start at 0. The code I have is as follows:
<data noupdate = "1"> <record forcecreate = "True" id = "vendor_monthly_counter" model = "ir.cron"> <field name = "name"> Monthly worker accountant </field> <field eval = "True" name = "active" /> <field name = "user_id" ref = "base.user_root" /> <field name = "interval_number"> 1 </field> <field name = "interval_type"> months </field> <field name = "numbercall"> - 1 </field> <field ref = "model_proyecto_rc_trabajador" name = "model_id" /> <field name = "state"> code </field> <field name = "code"> model.get_realized_sales () </field> <field eval = "False" name = "doall" /> <field name = "function"> True </fieldpy get_realized_sales
class worker(models.Model): _name = 'project_rc.worker' _rec_name = 'name' name = fields.Char(string="Name", required=True) charge = fields.Selection( [('seller', 'Seller'), ('cashier', 'Cashier')], string="Cargo", required=True) sales_counter = fields.Integer( string="Sales made", compute="get_realized_sales", store=True) document_ids = fields.One2many( comodel_name='project_rc.document', inverse_name='worker_id', string='Invoice', required=true) @api.depends ('document_ids') def get_realized_sales(self): for rec in self: document = rec.document_ids.filtered( lambda r: r.type_movimiento_id and\ r.type_movement_id.type_movement == 'sale') rec.sales_counter = len(document)
What could I miss, some py? and how would that py be?