Skip to Content
Menu
This question has been flagged
4 Replies
5120 Views

Hello guys,

I have created 4 new filters in account.invoice. Invoices of the day, invoices of the week, invoices of the month and invoices of the current year.

All works very well. But the week filter (Ventes hebdomadaires - CF) doesn't work and I don't know why.



My file filters.xml :

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="0">

<record id="filters_lapagept.ventes_annuelles_cf" model="ir.filters">
<field name="name">Ventes annuelles - CF</field>
<field name="model_id">account.invoice</field>
<field name="is_default" eval="False" />
<field name="user_id" ref="" />
<field name="domain">[['invoice_year','=',time.strftime('%Y')]]</field>
<field name="context">{'group_by':['period_id']}</field>
</record>
<record id="filters_lapagept.ventes_mensuelles_cf" model="ir.filters">
<field name="name">Ventes mensuelles - CF</field>
<field name="model_id">account.invoice</field>
<field name="is_default" eval="False" />
<field name="user_id" ref="" />
<field name="domain">[['invoice_month','=',time.strftime('%m')]]</field>
<field name="context">{}</field>
</record>
<record id="filters_lapagept.ventes_hebdomadaires_cf" model="ir.filters">
<field name="name">Ventes hebdomadaires - CF</field>
<field name="model_id">account.invoice</field>
<field name="is_default" eval="False" />
<field name="user_id" ref="" />
<field name="domain">[['invoice_week','=',time.strftime('%U')]]</field>
<field name="context">{}</field>
</record>
<record id="filters_lapagept.ventes_quotidiennes_cf" model="ir.filters">
<field name="name">Ventes quotidiennes - CF</field>
<field name="model_id">account.invoice</field>
<field name="is_default" eval="False" />
<field name="user_id" ref="" />
<field name="domain">[['date_invoice','=',time.strftime('%Y-%m-%d')]]</field>
<field name="context">{}</field>
</record>

</data>
</openerp>



My file classes.py :

from openerp import models, fields, api, _

import logging
_logger = logging.getLogger(__name__)

import datetime
from datetime import datetime

class account_invoice(models.Model):
_inherit = "account.invoice"

invoice_year = fields.Char(compute='_findyear', string="Annee de la facture", store=True)
invoice_month = fields.Char(compute='_findmonth',string="Mois de la facture", store=True)
invoice_week = fields.Char(compute='_findweek',string="Semaine de la facture", store=True)

@api.depends('date_invoice')
def _findyear(self):
self.invoice_year = datetime.now().strftime('%Y')
@api.depends('date_invoice')
def _findmonth(self):
self.invoice_month = datetime.now().strftime('%m')
@api.depends('date_invoice')
def _findweek(self):
self.invoice_week = datetime.now().strftime('%U')


But I always get this error for the week filter :


Error: Failed to evaluate search criterions:
{"code":400,"message":"Evaluation Error","data":{"type":"local_exception","debug":"Local evaluation failure\nValueError: No known conversion for %U\n\n{\"domains\":[[[\"type\",\"=\",\"out_invoice\"]],\"[['invoice_week','=',time.strftime('%U')]]\"],\"contexts\":[{\"lang\":\"en_US\",\"tz\":\"America/Montreal\",\"uid\":1,\"default_type\":\"out_invoice\",\"type\":\"out_invoice\",\"journal_type\":\"sale\",\"params\":{\"action\":586}},\"{}\"],\"group_by_seq\":[\"{}\"]}"}}

http://cferalma.com/web/static/src/js/views.js:852


Thanks all for your idea!


Avatar
Discard
Author Best Answer

Here is the domain we really needed :


<record id="filters_lapagept.ventes_hebdomadaires_cf" model="ir.filters">

        <field name="name">Ventes hebdomadaires - CF</field>

        <field name="model_id">account.invoice</field>

        <field name="is_default" eval="False" />

        <field name="user_id" ref="" />

        <field name="domain">[('date_invoice','&gt;=', ((context_today()).strftime('%Y-%m-%d'))), ('date_invoice','&lt;=', ((context_today()+datetime.timedelta(days=7)).strftime('%Y-%m-%d')))]</field>

        <field name="context">{'group_by':'date_invoice'}</field>

</record>


This way, we get only invoice of the actual week. Not invoices from the last week.


Avatar
Discard

That domain is for another scenario, not for your original question problem that was answered ok by my answer, or not? That answer should be the accepted one and up voted, not your resumed and extended answer with new particular problems solved. Just my opinion

Author

Axel, your domain returns also invoice for the last week. With my python function, I really put the number of the current week in my database. I never talked about the last week. Sorry. I have verified before to put my answer as the good one. @api.depends('date_invoice') def _findweek(self): self.invoice_week = datetime.now().strftime('%U')

Author

My goal on this forum is not to bypass everybody and do bad things...

Happy to see that you solve your problem. The domain I posted using context_today to get the actual week number was just the way to fix your original domain
[['invoice_week','=',time.strftime('%U')]]
that was supposed to return the actual week number, nothing more

Best Answer

Hi @Pascal, very interesting thing/bug happened to you. You could report it to Odoo on Github.

Note: I'm still waiting for your feedback of one or two of my answers to your question.

The error that you are seen is from pyeval.js implementation of time.strftime that rely on the partially implemented datetime.datetime.strftime, all of this in javascript. Here is the formats that is supported by the function and the error you are seen:

strftime: function () {
var self = this;
var args = py.PY_parseArgs(arguments, 'format');
return py.str.fromJSON(args.format.toJSON()
.replace(/%([A-Za-z])/g, function (m, c) {
switch (c) {
case 'Y': return _.str.sprintf('%04d', self.year);
case 'm': return _.str.sprintf('%02d', self.month);
case 'd': return _.str.sprintf('%02d', self.day);
case 'H': return _.str.sprintf('%02d', self.hour);
case 'M': return _.str.sprintf('%02d', self.minute);
case 'S': return _.str.sprintf('%02d', self.second);
}
throw new Error('ValueError: No known conversion for ' + m);
}));
},

Your problem can be solved by change this record domain:

<record id="ventes_hebdomadaires_cf" model="ir.filters">
<field name="name">Ventes hebdomadaires - CF</field>
<field name="model_id">account.invoice</field>
<field name="is_default" eval="False" />
<field name="user_id" ref="" />
<field name="domain">[['invoice_week','=',context_today().weekday()]]</field>
<field name="context">{}</field>
</record>

Cheers

Avatar
Discard
Author

Thanks for this answer. Will try it tomorrow. I will check old posts to find where I owe you some answers (sorry for this, I will correct it).

Related Posts Replies Views Activity
1
Jun 24
3692
0
Feb 24
534
1
Feb 23
2302
8
Apr 22
82462
1
Oct 21
1526