Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

SQL Querry for Dynamic View

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
querysqldynamicmodelodoo16features
1 Răspunde
3028 Vizualizări
Imagine profil
Alark Kulkarni

Dear All,

I'm creating a dynamic tree view using SQL query in which information is pulled from different models. The pulled information is jumbled and there is no linking of the information as the model is varied. For example, if we take SO & SOL, the SO number does not show the same SOL related to that SO number.

py is:


class DmrrReport(models.Model):
_name = "dmrr.report"
_description = "DMRR Report"
_auto = False

# Purchase Order Lines
product_id = fields.Many2one('product.product', string="Product")
description = fields.Text(string="Product Description")
# hsn_code = fields.Char(string="HSN/SAC Code")
product_qty = fields.Float(string="Quantity")
price_unit = fields.Float(string="Unit Price")
price_subtotal = fields.Char(string="Product Value")
# taxes_id = fields.Many2many('account.tax', string="Taxes")
product_uom = fields.Many2one('uom.uom', string="Unit")
price_total = fields.Char(string="Total Purchase Cost")

# Purchase Order
partner_id = fields.Many2one('res.partner', string="Vendor")
job_num = fields.Char(string="Job No.")
po_wo_date = fields.Date(string="PO/WO Date")

#Account Move / Bill Creation
bill_number = fields.Char(string="Bill No.")
invoice_date = fields.Date(string="Bill Date")

# # Stock Picking
stock_challan = fields.Char(string="Challan No.")
challan_date = fields.Date(string="Challan Date")
stock_grn = fields.Char(string="GRN No.")
effective_date = fields.Date(String="Date")
vehicle_no = fields.Char(String="Vehicle No.")
entry_gate_no = fields.Char(String="Entry Gate No.")
origin = fields.Char(String="PO/WO No.")

def init(self):
tools.drop_view_if_exists(self._cr, 'dmrr_report')
self._cr.execute("""
CREATE or REPLACE VIEW dmrr_report AS(
SELECT row_number() OVER () AS id, line.product_id, line.description, line.product_qty,
line.price_unit, line.partner_id, line.job_num, line.stock_challan, line.stock_grn,
line.vehicle_no, line.effective_date, line.entry_gate_no, line.product_uom, line.price_subtotal,
line.price_total, line.bill_number, line.invoice_date, line.origin, line.po_wo_date,
line.challan_date FROM (
SELECT pol.product_id as product_id,
pol.name as description,
pol.product_qty as product_qty,
pol.price_unit as price_unit,
pol.price_subtotal as price_subtotal,
pol.price_total as price_total,
pol.product_uom as product_uom,
po.partner_id as partner_id,
po.job_num as job_num,
po.effective_date as effective_date,
po.date_po as po_wo_date,
st.challan as stock_challan,
st.challan_date as challan_date,
st.grn as stock_grn,
st.vehicle_no as vehicle_no,
st.origin as origin,
st.entry_gate_no as entry_gate_no,
am.ref as bill_number,
am.invoice_date as invoice_date
FROM purchase_order_line pol
JOIN purchase_order po ON (po.id = pol.order_id)
JOIN account_move am ON (am.id = pol.order_id)
JOIN stock_picking st ON (st.id = pol.order_id)
) line
)""")

Thank you in advance

0
Imagine profil
Abandonează
Imagine profil
Hans Rickhoff 🚀 https://obd.digital
Cel mai bun răspuns

Your code is a solid start, but if the SO (Sales Order) numbers and SOL (Sales Order Lines) aren't matching up as expected, it's likely because the linking logic in your SQL needs a tweak. Let's straighten this out!

First, the heart of your query is trying to stitch together data from different models: purchase_order_line (POL), purchase_order (PO), account_move (AM), and stock_picking (ST). But, your JOIN conditions seem a bit off, especially linking account_move and stock_picking directly to purchase_order_line using pol.order_id. This linkage assumes account_move.id and stock_picking.id match purchase_order_line.order_id, which is unlikely unless there's a very unique setup in your database.

Here's a more aligned approach, focusing on the purchase side. Since the original question mixes SO (Sales Order) and PO (Purchase Order) terminology, I'll stick to the PO context given your code. If you need to incorporate SO information, the logic would be similar, just adapted to sales models (sale.order, sale.order.line, etc.).

  1. Clarify the Relationships: Ensure that the relationships between purchase_order, purchase_order_line, account_move, and stock_picking are correctly defined. Usually:
    • A purchase_order can be linked to account_move records (bills) through a field like invoice_ids or a similar mechanism, not directly through id matching.
    • stock_picking records are linked to purchase_order records either directly via a field on stock_picking (like purchase_id) or through operational types and source documents.
  2. Adjust the SQL Query: Use proper JOIN conditions that reflect these relationships. You might need to:
    • Join account_move to purchase_order through a field that represents the connection (often through a many2many relationship, which may require an intermediate join).
    • Similarly, adjust the join condition between stock_picking and purchase_order to use the correct relational field.

Odoo Beratung Deutschland

1
Imagine profil
Abandonează
Enjoying the discussion? Don't just read, join in!

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

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
Moving accessory products to alternative products
sql odoo16features
Imagine profil
0
apr. 24
1269
How to solved this SQL error ?? Rezolvat
query sql
Imagine profil
Imagine profil
1
sept. 21
3813
How to print tree_view from sql query in odoo 11
query sql tree_view
Imagine profil
0
oct. 21
1691
[Odoo16] ERROR: could not serialize access due to concurrent update
community error query odoo16features
Imagine profil
1
sept. 24
3208
Hello, I would like to know how I could execute this query only for one record and not have it executed on the entire table.
python query records sql
Imagine profil
Imagine profil
1
apr. 24
2459
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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