Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

how to pass parameters using with_context ?

Subscriure's

Get notified when there's activity on this post

This question has been flagged
pythonodoo10
3 Respostes
22249 Vistes
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
Descartar
Niyas Raphy (Walnut Software Solutions)

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

Shaffaf
Autor

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

Avatar
Sehrish
Best Answer

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
Descartar
Enjoying the discussion? Don't just read, join in!

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

Registrar-se
Related Posts Respostes Vistes Activitat
error ConfigParser.ParsingError: File contains parsing errors
python odoo10
Avatar
0
de març 21
7604
odoo/python invalidate_all() Solved
python odoo10
Avatar
Avatar
Avatar
2
de gen. 19
8248
Function Python for Odoo 10
python odoo10
Avatar
Avatar
1
de des. 18
3767
calculate expiration date from production date and duration
python odoo10
Avatar
Avatar
1
de jul. 18
8183
odoo10 error,i can't submit helpdesk ticket Ask Question in our own server
python odoo10
Avatar
Avatar
1
d’abr. 18
4662
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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