Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

How to get report data based on company_id

Naroči se

Get notified when there's activity on this post

This question has been flagged
reportpython2.7openerpodooV8
1 Odgovori
6913 Prikazi
Avatar
youta

Hello,

I'm trying to get Employees' payroll data for each company in a report.

Here's my code:

in my wizard:

class hr_wps_report(osv.osv_memory):

_name = 'hr.wps.report'

_description = 'WPS Report'

_columns = {

'date_from':fields.date("Start Date"),

'date_to':fields.date("End Date"),

'company_id': fields.many2one('res.company', 'Company', select=True, required=False),

}

_defaults = {

'date_from': lambda *a: time.strftime('%Y-%m-01'),

'date_to': lambda *a: str(datetime.now() + relativedelta.relativedelta(months=+1, day=1, days=-1))[:10],

'company_id': lambda self, cr, uid, context: self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id,

}

def print_report(self, cr, uid, ids, data, context=None):

if context is None:

context = {}

data['form'] = self.read(cr, uid, ids, ['date_from', 'date_to', 'company_id'], context=context)[0]

return self.pool['report'].get_action(cr, uid, [], 'hr_wps.report_wpsreport', data=data, context=context)


in my report:

class wpsreport(report_sxw.rml_parse):

def __init__(self, cr, uid, name, context):

super(wpsreport, self).__init__(cr, uid, name, context=context)

self.localcontext.update({

'time': time,

'get_lines': self._get_lines,

})

def set_context(self, objects, data, ids, report_type=None):

self.date_start = data['form'].get('date_from', time.strftime('%Y-%m-%d'))

self.date_end = data['form'].get('date_to', time.strftime('%Y-%m-%d'))

self.company_id = data['form'].get('company_id')

return super(wpsreport, self).set_context(objects, data, ids, report_type=report_type)

def _get_lines(self, form):

res = []

self.cr.execute("""SELECT hr_employee.name_related,

(SELECT hr_payslip_line.total

FROM hr_payslip_line, hr_payslip

WHERE hr_employee.id = hr_payslip.employee_id

AND hr_payslip_line.slip_id = hr_payslip.id

AND hr_payslip_line.code = 'BASIC'

AND hr_payslip.date_from BETWEEN %s AND %s) as basic,

(SELECT hr_payslip_line.total

FROM hr_payslip_line, hr_payslip

WHERE hr_employee.id = hr_payslip.employee_id

AND hr_payslip_line.slip_id = hr_payslip.id

AND hr_payslip_line.code = 'ALLOWANCES'

AND hr_payslip.date_from BETWEEN %s AND %s) as total_allowance,

(SELECT hr_payslip_line.total

FROM hr_payslip_line, hr_payslip

WHERE hr_employee.id = hr_payslip.employee_id

AND hr_payslip_line.slip_id = hr_payslip.id

AND hr_payslip_line.code = 'DEDUCTIONS'

AND hr_payslip.date_from BETWEEN %s AND %s) as total_deduction,

(SELECT hr_payslip_line.total

FROM hr_payslip_line, hr_payslip

WHERE hr_employee.id = hr_payslip.employee_id

AND hr_payslip_line.slip_id = hr_payslip.id

AND hr_payslip_line.code = 'NET'

AND hr_payslip.date_from BETWEEN %s AND %s) as total

FROM hr_employee,

hr_payslip,

res_company

WHERE hr_payslip.employee_id = hr_employee.id

AND hr_payslip.company_id = res_company.id

AND hr_payslip.date_from BETWEEN %s AND %s

AND hr_payslip.company_id = %s""", (self.date_start, self.date_end, self.date_start, self.date_end, self.date_start, self.date_end, self.date_start, self.date_end, self.date_start, self.date_end, self.company_id))

 

employees = self.cr.dictfetchall()

for emp in employees:

value = {}

value['name_related'] = emp['name_related']

value['basic'] = emp['basic']

value['total_allowance'] = emp['total_allowance']

value['total_deduction'] = emp['total_deduction']

value['total'] = emp['total']

value['No_working_days'] = 30

value['extra_hours'] = 0

res.append(value)

return res


But I'm getting Error of:

QWebException: "invalid input syntax for integer: "Yourcompany" 

AND hr_payslip.company_id = ARRAY[9, 'Yourcompany']

How to fix it?

0
Avatar
Opusti
Avatar
Qutechs, Ahmed M.Elmubarak
Best Answer

Hello,

Try these:

self.company_id.id

or 

self.company_id[0]

instead of self.company_id in the query ..


Hope it'll work

1
Avatar
Opusti
youta
Avtor

This one worked self.company_id[0] Thank you very much.. you're my hero Ahmed :D However, can you explain it.. I mean the error, in other words what is the difference between self.company_id[0] and self.company_id

Qutechs, Ahmed M.Elmubarak

Thanx so much for cheering :] . When you use self.company_id it will return a list containing the [ID, name of the record] as your case here [9, 'Yourcompany'], which your query don't expect that value, so you just need to fetch the ID from the list, when you use the self.company_id[0] then you're fetching the first element in the list which is the Id ...

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

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

Prijavi
Related Posts Odgovori Prikazi Aktivnost
Update One2many Fields in the view
python2.7 openerp odooV8
Avatar
Avatar
1
apr. 17
3560
CRITICAL travel-management openerp.modules.module: to_field Solved
python2.7 openerp odooV8
Avatar
Avatar
1
jan. 16
4235
How to fix a group and show related user in drop down ??
groups python2.7 openerp odooV8
Avatar
0
jul. 19
497
Issue in many2many_kanban widget unable to delete the attachment ?
python2.7 openerp odoo odooV8
Avatar
0
jul. 19
848
Record rule for project customer when it's login
python2.7 record_rules openerp odooV8
Avatar
1
jul. 19
585
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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