Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Domain, filter date and month

Subscribe

Get notified when there's activity on this post

This question has been flagged
filterdomaindatesalemonth
2 Replies
37260 Views
Avatar
Youri Lebarch

Hello,
I try to create a filter domain in sale.report as : Month(order_date) = month(current_date) AND Day(order_date) <= Day(current_date).



<filter string="New Filter" domain="[(('date').strftime('%%m'),'=',((context_today()).strftime('%%m'))),
            (('date').strftime('%%d'),'&gt;=', ((context_today()).strftime('%%d')))]"/> 


I have a problem in left side of domain : ('date'), System say: AttributeError: object has no attribute 'strftime'.

try many combination, but response it's same.

Have you an idea ? What is the type of object 'date' ?


Thanks

1
Avatar
Discard
Avatar
Youri Lebarch
Author Best Answer

Temur, thanks for your response. 
I try all of that, but always same problem ("AttributeError: object has no attribute 'strftime'."). An other idea ?


<filter string="This 1" domain="[(strptime('date','%%m'),'=', ((context_today()).strftime('%%m')))]"/> <filter string="This 2" domain="[(time.strptime('date','%%m'),'=', ((context_today()).strftime('%%m')))]"/> <filter string="This 3" domain="[(date.strptime('date','%%m'),'=', ((context_today()).strftime('%%m')))]"/> <filter string="This 5" domain="[(datetime.date.strptime('date','%%Y-%%m-%%d'),'=', ((context_today()).strftime('%%m')))]"/> <filter string="This 6" domain="[(datetime.time.strptime('date','%%Y-%%m-%%d'),'=', ((context_today()).strftime('%%m')))]"/> <filter string="This 7" domain="[(datetime.datetime.strptime('date','%%m'),'=', ((context_today()).strftime('%%m')))]"/> <filter string="This 4" domain="[(datetime.strptime('date','%%Y-%%m-%%d'),'=', ((context_today()).strftime('%%m')))]"/> <filter string="This 5" domain="[(datetime.date().strptime('date','%%m'),'=', ((context_today()).strftime('%%m')))]"/> <filter string="This 6" domain="[(datetime.time().strptime('date','%%m'),'=', ((context_today()).strftime('%%m')))]"/> <filter string="This 7" domain="[(datetime.datetime().strptime('date','%%m'),'=', ((context_today()).strftime('%%m')))]"/> <filter string="This 5" domain="[(datetime.date().strptime('date','%%Y-%%m-%%d'),'=', ((context_today()).strftime('%%m')))]"/> <filter string="This 6" domain="[(datetime.time().strptime('date','%%Y-%%m-%%d'),'=', ((context_today()).strftime('%%m')))]"/> <filter string="This 7" domain="[(datetime.datetime().strptime('date','%%Y-%%m-%%d'),'=', ((context_today()).strftime('%%m')))]"/> <filter string="This 10" domain="[(datetime.date('date'),'=', ((context_today()).strftime('%%m')))]"/> <filter string="This 11" domain="[(datetime.time('date'),'=', ((context_today()).strftime('%%m')))]"/> <filter string="This 12" domain="[(datetime.datetime('date'),'=', ((context_today()).strftime('%%m')))]"/> filter string="This 11" domain="[(datetime.time('date').strftime('%%m'),'=', ((context_today()).strftime('%%m')))]"/>


EDIT : 

Finally, i found the solution : sale.report is not a real model, it's a view. For add field, you need to overwrite select method. So : 

 class sale_report(osv.osv):
    _inherit = 'sale.report' 
    
    date_order_month = fields.Char(string='Date Month')
    date_order_day = fields.Char(string='Date Day')
    

    def _select(self):
        select_str = """
             SELECT min(l.id) as id,
                    l.product_id as product_id,
                    t.uom_id as product_uom,
                    sum(l.product_uom_qty / u.factor * u2.factor) as product_uom_qty,
                    sum(l.product_uom_qty * l.price_unit * (100.0-l.discount) / 100.0) as price_total,
                    count(*) as nbr,
                    s.date_order as date,
                    date_part('month', s.date_order) as date_order_month,
                    date_part('day', s.date_order) as date_order_day,
                    s.date_confirm as date_confirm,
                    s.partner_id as partner_id,
                    s.user_id as user_id,
                    s.company_id as company_id,
                    extract(epoch from avg(date_trunc('day',s.date_confirm)-date_trunc('day',s.create_date)))/(24*60*60)::decimal(16,2) as delay,
                    s.state,
                    t.categ_id as categ_id,
                    s.pricelist_id as pricelist_id,
                    s.project_id as analytic_account_id,
                    s.section_id as section_id
        """
        return select_str

1
Avatar
Discard
Temur

I never used any operation in a left part of condition, normally there is only field name in the left part... I'm curious if it's allowed/supported? if it works in general, then you have to strptime a 'date' first with it's original format %Y-%m-%d" and then strftime it to month using "%m" format:

domain = "[ ( datetime.datetime.strptime('date','%%Y-%%m-%%d').strftime('%%m'), '=' , context_today().strftime('%%m') ) ]"
here right side: context_today().strftime('%%m') is ok: in the left side if operations allowed here (other then simple field names) and 'date' will be inserted correctly than this should work. otherwise consider to add computed field, lets say named as 'date_month' and then use 'date_month' field as follows:
domain = "[ ( 'date_month', '=' , context_today().strftime('%%m') ) ]
I'm sure about second option, but if you'll get worked first one LMK about the final sollution...
Temur

most probably you'll be limited to use only field names in the left side of condition... computed field will resolve the problem in such case, as I suggested above

Youri Lebarch
Author

I think you are reason : left operand cannot be an object, juste a string. So i try your proposition but i can't add field in model sale_report. Fields are visible in UI in models but not in database Have you an idea ? class sale_report(osv.osv): _inherit = 'sale.report' date_month = fields.Char(string='Date Month') date_day = fields.Char(string='Date Day') I have not error message

Temur

Upvote for exploring of view based objects in odoo ;) I've not seen view based models in odoo before, it's a bit advanced approach. I've used view based models beyond odoo, actually it was in my "todo someday" list to find out how to use view based models in odoo orm. I thought they are not used here and I was going to do it myself. Thank you for revealing use case of such objects. I see now that there are also few other view based objects, but most of them are used in different reports, anyway no so wide usage and implementation also leaves something to be desired. I think they should be supported better and it should be possible to create/extend view based models more elegantly, rather than overriding _select and stuff like that.

Avatar
Temur
Best Answer

most probably "date" object in that context is date string already formatted as: "%Y-%m-%d" (like '2015-06-03'). if so, then you can't call strftime on string object and you get above mentioned error.


UPDATE:
try to add computed field date_month:

from openerp import models, fields, api 
from datetime import datetime as dt


class sale_report(models.Model):
_inherit = 'sale.report'

date_month = fields.Char(string='Date Month',compute='_get_date_month',store=True,readonly=True)

@api.one
@api.depends('date')
def _get_date_month(self):
self.date_month = dt.
strptime(self.date,'%Y-%m-%d').strftime('%m')

then in your filter you'll be able to use :

domain = "[ ( 'date_month', '=' , context_today().strftime('%%m') ) ]


1
Avatar
Discard
Youri Lebarch
Author

I find the solution, sale.report is not a real model, it's a view. For add field, you need to overwrite select method. So : class sale_report(osv.osv): _inherit = 'sale.report' date_order_month = fields.Char(string='Date Month') date_order_day = fields.Char(string='Date Day') def _select(self): select_str = """ SELECT min(l.id) as id, l.product_id as product_id, t.uom_id as product_uom, sum(l.product_uom_qty / u.factor * u2.factor) as product_uom_qty, sum(l.product_uom_qty * l.price_unit * (100.0-l.discount) / 100.0) as price_total, count(*) as nbr, s.date_order as date, date_part('month', s.date_order) as date_order_month, date_part('day', s.date_order) as date_order_day,

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
Filter by date of today with a delay
filter domain date
Avatar
Avatar
Avatar
3
Apr 16
41426
Filter many2one field with functional field
filter domain
Avatar
Avatar
Avatar
5
Sep 20
13686
In date field, is it possible to display month and year only?
date month
Avatar
1
Jan 20
8463
fillter by date
filter date
Avatar
Avatar
1
Sep 16
56
filter invoices for this month
filter date
Avatar
0
Mar 15
5566
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now