Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Why does my week filter not work in account.invoice?

By
Pascal Tremblay
on 12/4/15, 7:48 PM 979 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!


Pascal Tremblay
on 12/6/15, 9:14 PM
0

Pascal Tremblay

--Pascal Tremblay--
1312
| 5 2 7
Alma, Canada
--Pascal Tremblay--


Pascal Tremblay
On 12/7/15, 2:52 PM

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.


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

Axel Mendoza
on 12/7/15, 3:24 PM

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')

Pascal Tremblay
on 12/7/15, 3:29 PM

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

Pascal Tremblay
on 12/7/15, 3:31 PM

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

Axel Mendoza
on 12/8/15, 7:25 PM
1

Axel Mendoza

--Axel Mendoza--
10238
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 12/4/15, 11:59 PM

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

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).

Pascal Tremblay
on 12/6/15, 9:14 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 12/4/15, 7:48 PM
Seen: 979 times
Last updated: 12/27/15, 9:24 PM