Skip to Content
Odoo Menu
  • Log ind
  • Prøv gratis
  • Apps
    Økonomi
    • Bogføring
    • Fakturering
    • Udgifter
    • Regneark (BI)
    • Dokumenter
    • e-Signatur
    Salg
    • CRM
    • Salg
    • POS Butik
    • POS Restaurant
    • Abonnementer
    • Udlejning
    Hjemmeside
    • Hjemmesidebygger
    • e-Handel
    • Blog
    • Forum
    • LiveChat
    • e-Læring
    Forsyningskæde
    • Lagerbeholdning
    • Produktion
    • PLM
    • Indkøb
    • Vedligeholdelse
    • Kvalitet
    HR
    • Medarbejdere
    • Rekruttering
    • Fravær
    • Medarbejdersamtaler
    • Anbefalinger
    • Flåde
    Marketing
    • Markedsføring på sociale medier
    • E-mailmarketing
    • SMS-marketing
    • Arrangementer
    • Automatiseret marketing
    • Spørgeundersøgelser
    Tjenester
    • Projekt
    • Timesedler
    • Udkørende Service
    • Kundeservice
    • Planlægning
    • Aftaler
    Produktivitet
    • Dialog
    • Godkendelser
    • IoT
    • VoIP
    • Vidensdeling
    • WhatsApp
    Tredjepartsapps Odoo Studio Odoo Cloud-platform
  • Brancher
    Detailhandel
    • Boghandel
    • Tøjforretning
    • Møbelforretning
    • Dagligvarebutik
    • Byggemarked
    • Legetøjsforretning
    Mad og værtsskab
    • Bar og pub
    • Restaurant
    • Fastfood
    • Gæstehus
    • Drikkevareforhandler
    • Hotel
    Ejendom
    • Ejendomsmægler
    • Arkitektfirma
    • Byggeri
    • Ejendomsadministration
    • Havearbejde
    • Boligejerforening
    Rådgivning
    • Regnskabsfirma
    • Odoo-partner
    • Marketingbureau
    • Advokatfirma
    • Rekruttering
    • Audit & certificering
    Produktion
    • Tekstil
    • Metal
    • Møbler
    • Fødevareproduktion
    • Bryggeri
    • Firmagave
    Heldbred & Fitness
    • Sportsklub
    • Optiker
    • Fitnesscenter
    • Kosmetolog
    • Apotek
    • Frisør
    Håndværk
    • Handyman
    • IT-hardware og support
    • Solenergisystemer
    • Skomager
    • Rengøringsservicer
    • VVS- og ventilationsservice
    Andet
    • Nonprofitorganisation
    • Miljøagentur
    • Udlejning af billboards
    • Fotografi
    • Cykeludlejning
    • Softwareforhandler
    Gennemse alle brancher
  • Community
    Få mere at vide
    • Tutorials
    • Dokumentation
    • Certificeringer
    • Oplæring
    • Blog
    • Podcast
    Bliv klogere
    • Udannelselsesprogram
    • Scale Up!-virksomhedsspillet
    • Besøg Odoo
    Få softwaren
    • Download
    • Sammenlign versioner
    • Udgaver
    Samarbejde
    • Github
    • Forum
    • Arrangementer
    • Oversættelser
    • Bliv partner
    • Tjenester til partnere
    • Registrér dit regnskabsfirma
    Modtag tjenester
    • Find en partner
    • Find en bogholder
    • Kontakt en rådgiver
    • Implementeringstjenester
    • Kundereferencer
    • Support
    • Opgraderinger
    Github Youtube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Få en demo
  • Prissætning
  • Hjælp

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

  • CRM
  • e-Commerce
  • Bogføring
  • Lager
  • PoS
  • Projekt
  • MRP
All apps
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Hjælp

how to pass parameters using with_context ?

Tilmeld

Få besked, når der er aktivitet på dette indlæg

Dette spørgsmål er blevet anmeldt
pythonodoo10
3 Besvarelser
22357 Visninger
Avatar
Shaffaf

I have a print_excel method which is used to create an excel file for general ledger. I have generated all the data but there is some issue while passing data into the query. I couldn't fix the bug please someone helps me out.


account_report_general_ledger.py

def print_excel(self):

filename= 'GeneralLedger.xls'

ctx = self.env.context

data = self.get_data_for_xls()

sortby = data['form']['sortby']

init_balance = data['form']['initial_balance']

date_from = data['form']['date_from']

date_to = data['form']['date_to']

od_move_lines = self.get_move_line_ids()

od_move_lines = self.env['account.move.line'].browse(od_move_lines)

search_cond = ''' '''

if od_move_lines:

search_cond = search_cond + ''' and l.id in %s '''

if data['form'].get('journal_ids', False):

codes = [journal.code for journal in self.env['account.journal'].search([('id', 'in', data['form']['journal_ids'])])]

self.model = self.env.context.get('active_model')

accounts = self.env['account.account'].browse(ctx.get('active_id')) if self.model == 'account.account' else self.env['account.account'].search([])

display_account = data['form']['display_account']

ctx = {'dt_cont':{'date_from':date_from,'date_to':date_to}}

movelines = self.env['report.account.report_generalledger'].with_context(ctx)._get_account_move_entry( accounts, init_balance, sortby, display_account,od_move_lines,search_cond) ##ISSUE

account_general_ledger.py

def _get_account_move_entry(self, accounts, init_balance, sortby, display_account,od_move_lines,search_cond):

"""

:param:

accounts: the recordset of accounts

init_balance: boolean value of initial_balance

sortby: sorting by date or partner and journal

display_account: type of account(receivable, payable and both)

Returns a dictionary of accounts with following key and value {

'code': account code,

'name': account name,

'debit': sum of total debit amount,

'credit': sum of total credit amount,

'balance': total balance,

'amount_currency': sum of amount_currency,

'move_lines': list of move line

}

"""

cr = self.env.cr

context=self.env.context

MoveLine = self.env['account.move.line']

move_lines = dict(map(lambda x: (x, []), accounts.ids))

# Prepare initial sql query and Get the initial move lines

if init_balance:

init_tables, init_where_clause, init_where_params = MoveLine.with_context(date_from=self.env.context.get('date_from'), date_to=False, initial_bal=True)._query_get()

init_wheres = [""]

if init_where_clause.strip():

init_wheres.append(init_where_clause.strip())

init_filters = " AND ".join(init_wheres)

filters = init_filters.replace('account_move_line__move_id', 'm').replace('account_move_line', 'l')

sql = ("""SELECT 0 AS lid, cc.name AS cost_center, l.account_id AS account_id, '' AS ldate, '' AS lcode, NULL AS amount_currency, '' AS lref, 'Initial Balance' AS lname, COALESCE(SUM(l.debit),0.0) AS debit, COALESCE(SUM(l.credit),0.0) AS credit, COALESCE(SUM(l.debit),0) - COALESCE(SUM(l.credit), 0) as balance, '' AS lpartner_id,\

'' AS move_name, '' AS mmove_id, '' AS currency_code,\

NULL AS currency_id,\

'' AS invoice_id, '' AS invoice_type, '' AS invoice_number,\

'' AS partner_name\

FROM account_move_line l\

LEFT JOIN account_move m ON (l.move_id=m.id)\

LEFT JOIN orchid_account_cost_center cc ON (l.orchid_cc_id=cc.id)\

LEFT JOIN res_currency c ON (l.currency_id=c.id)\

LEFT JOIN res_partner p ON (l.partner_id=p.id)\

LEFT JOIN account_invoice i ON (m.id =i.move_id)\

JOIN account_journal j ON (l.journal_id=j.id)\

WHERE l.account_id IN %s """ + search_cond + filters + ' GROUP BY l.account_id,l.partner_id,cc.name')

params = ()

print "where params>>>>>>>>>>>>>>>>>>>>>>>",init_where_params #####NO VALUES

if od_move_lines:

params = (tuple(accounts.ids),tuple(od_move_lines.ids),) + tuple(init_where_params)

else:

params = (tuple(accounts.ids),) + tuple(init_where_params)

cr.execute(sql, params)

for row in cr.dictfetchall():

if move_lines[row['account_id']]:

move_lines[row['account_id']][0]['credit'] = move_lines[row['account_id']][0]['credit'] + row['credit']

move_lines[row['account_id']][0]['debit'] = move_lines[row['account_id']][0]['debit'] + row['debit']

move_lines[row['account_id']][0]['balance'] = move_lines[row['account_id']][0]['balance'] + row['balance']

else:

move_lines[row.pop('account_id')].append(row)

sql_sort = 'l.date, l.move_id'

if sortby == 'sort_journal_partner':

sql_sort = 'j.code, p.name, l.move_id'


 

0
Avatar
Kassér
Niyas Raphy (Walnut Software Solutions)

I think it will be better if you can post the issue / error message along with the question

Shaffaf
Forfatter

There was no error and the issue was i am getting 2 different initial balance values in pdf and excel.

Avatar
Sehrish
Bedste svar

I don't know what you are looking for but try this may be its helpful to you.

return self.with_context({'signal':'call_from_desination', 'current_object':self})

0
Avatar
Kassér
Enjoying the discussion? Don't just read, join in!

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

Tilmeld dig
Related Posts Besvarelser Visninger Aktivitet
error ConfigParser.ParsingError: File contains parsing errors
python odoo10
Avatar
0
mar. 21
7698
odoo/python invalidate_all() Løst
python odoo10
Avatar
Avatar
Avatar
2
jan. 19
8358
Function Python for Odoo 10
python odoo10
Avatar
Avatar
1
dec. 18
3827
calculate expiration date from production date and duration
python odoo10
Avatar
Avatar
1
jul. 18
8238
odoo10 error,i can't submit helpdesk ticket Ask Question in our own server
python odoo10
Avatar
Avatar
1
apr. 18
4726
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Oversættelser
Tjenester
  • Odoo.sh-hosting
  • Support
  • Opgradere
  • Individuelt tilpasset udvikling
  • Uddannelse
  • Find en bogholder
  • Find en partner
  • Bliv partner
Om os
  • Vores virksomhed
  • Brandaktiver
  • Kontakt os
  • Stillinger
  • Arrangementer
  • Podcast
  • Blog
  • Kunder
  • Juridiske dokumenter • Privatlivspolitik
  • Sikkerhedspolitik
الْعَرَبيّة 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 er en samling open source-forretningsapps, der dækker alle dine virksomhedsbehov – lige fra CRM, e-handel og bogføring til lagerstyring, POS, projektledelse og meget mere.

Det unikke ved Odoo er, at systemet både er brugervenligt og fuldt integreret.

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