Siirry sisältöön
Odoo Menu
  • Kirjaudu sisään
  • Kokeile ilmaiseksi
  • Sovellukset
    Talous
    • Kirjanpito
    • Laskutus
    • Kulut
    • Datataulukot (BI)
    • Asiakirjat
    • Allekirjoita
    Myynti
    • CRM
    • Myynti
    • Kassajärjestelmä myymälään
    • Kassajärjestelmä ravintolaan
    • Tilaukset
    • Vuokraus
    Verkkosivut
    • Verkkosivun Rakennustyökalu
    • Verkkokauppa
    • Blogi
    • Foorumi
    • Livechat
    • Verkko-oppiminen
    Toimitusketju
    • Varastointi
    • Tuotanto
    • Tuotteen elinkaaren hallinta (PLM)
    • Ostot
    • Huolto
    • Laatu
    Henkilöstöhallinto
    • Työntekijät
    • Rekrytointi
    • Vapaat
    • Arvioinnit
    • Suositukset
    • Kuljetuskalusto
    Markkinointi
    • Somemarkkinointi
    • Sähköpostimarkkinointi
    • Tekstiviestimarkkinointi
    • Tapahtumat
    • Markkinoinnin automaatio
    • Kyselyt
    Palvelut
    • Projekti
    • Työaikakirjaukset
    • Kenttähuolto
    • Asiakaspalvelu
    • Suunnittelu
    • Ajanvaraukset
    Tuottavuus
    • Viestintä
    • Hyväksynnät
    • IoT
    • IP-puhe
    • Tietokirjasto
    • WhatsApp
    Kolmannen osapuolen sovellukset Odoo-Studio Odoo-Pilvialusta
  • Toimialat
    Vähittäiskauppa
    • Kirjakauppa
    • Vaatekauppa
    • Huonekaluliike
    • Ruokakauppa
    • Laitteistokauppa
    • Lelukauppa
    Ruoka & Majoitus
    • Baari ja Pubi
    • Ravintola
    • Pikaruoka
    • Majatalo
    • Juomien jakelija
    • Hotelli
    Kiinteistöt
    • Kiinteistönvälitystoimisto
    • Arkkitehtitoimisto
    • Rakentaminen
    • Kiinteistönhallinta
    • Puutarhanhoito
    • Kiinteistön omistajien yhdistys
    Konsultointi
    • Tilitoimisto
    • Odoo-kumppani
    • Markkinointitoimisto
    • Lakitoimisto
    • Osaajahankinta
    • Tilintarkastus & sertifiointi
    Tuotanto
    • Tekstiili
    • Metalli
    • Huonekalut
    • Ruoka
    • Panimo
    • Yrityslahjat
    Terveys & Liikunta
    • Urheiluseura
    • Silmälasiliike
    • Kuntokeskus
    • Hyvinvointialan ammattilaiset
    • Apteekki
    • Kampaamo
    Kaupat
    • Yleismies
    • IT-laitteisto & Tuki
    • Aurinkoenergiajärjestelmät
    • Suutari
    • Siivouspalvelut
    • LVI-palvelut
    Muut
    • Voittoa tavoittelematon järjestö
    • Ympäristötoimisto
    • Mainostaulujen vuokraus  
    • Valokuvaus
    • Leasing-pyörät
    • Ohjelmistojen jälleenmyyjä
    Selaa kaikkia toimialoja
  • Yhteisö
    Opi
    • Kurssit
    • Dokumentaatio
    • Todistukset
    • Koulutus
    • Blogi
    • Podcast
    Kannusta kouluttautumaan
    • Koulutusohjelmat
    • Scale Up! Liiketoimintapeli
    • Vieraile Odoolla
    Hanki ohjelmisto
    • Lataa
    • Vertaile versioita
    • Julkaisut
    Tee yhteistyötä
    • Github
    • Foorumi
    • Tapahtumat
    • Käännökset
    • Ryhdy kumppaniksi
    • Kumppanipalvelut
    • Rekisteröi tilitoimistosi
    Hanki palveluja
    • Löydä kumppani
    • Löydä kirjanpitäjä
    • Varaa asiantuntijatapaaminen
    • Implementaatiopalvelut
    • Asiakasreferenssit
    • Tuki
    • Versionkorotukset
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Varaa demo
  • Hinnoittelu
  • Asiakaspalvelu

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

  • CRM
  • e-Commerce
  • Kirjanpito
  • Varastointi
  • PoS
  • Projekti
  • MRP
All apps
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Kaikki kirjoitukset Ihmiset Merkit
Tunnisteet (Näytä kaikki)
odoo accounting v14 pos v15
Tietoa tästä foorumista
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Kaikki kirjoitukset Ihmiset Merkit
Tunnisteet (Näytä kaikki)
odoo accounting v14 pos v15
Tietoa tästä foorumista
Apua

SQL Querry for Dynamic View

Tilaa

Saat ilmoituksen, kun tähän viestiin ilmaantuu aktiviteettia

Tämä kysymys on merkitty
querysqldynamicmodelodoo16features
1 Vastaa
3048 Näkymät
Avatar
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
Avatar
Hylkää
Avatar
Hans Rickhoff 🚀 https://obd.digital
Paras vastaus

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
Avatar
Hylkää
Nautitko keskustelusta? Älä vain lue, vaan osallistu!

Luo tili jo tänään nauttiaksesi yksinoikeusominaisuuksista ja osallistuaksesi mahtavaan yhteisöömme!

Rekisteröidy
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
Moving accessory products to alternative products
sql odoo16features
Avatar
0
huhtik. 24
1271
How to solved this SQL error ?? Ratkaistu
query sql
Avatar
Avatar
1
syysk. 21
3838
How to print tree_view from sql query in odoo 11
query sql tree_view
Avatar
0
lokak. 21
1691
[Odoo16] ERROR: could not serialize access due to concurrent update
community error query odoo16features
Avatar
1
syysk. 24
3211
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
Avatar
Avatar
1
huhtik. 24
2477
Yhteisö
  • Kurssit
  • Dokumentaatio
  • Foorumi
Avoin lähdekoodi
  • Lataa
  • Github
  • Runbot
  • Käännökset
Palvelut
  • Odoo.sh hosting
  • Tuki
  • Versionkorotus
  • Räätälöidyt kehitykset
  • Koulutus
  • Löydä kirjanpitäjä
  • Löydä kumppani
  • Ryhdy kumppaniksi
Meistä
  • Yrityksemme
  • Tavaramerkki
  • Ota yhteyttä
  • Työpaikat
  • Tapahtumat
  • Podcast
  • Blogi
  • Asiakkaat
  • Oikeudellinen ilmoitus • Yksityisyys
  • Tietoturva
الْعَرَبيّة 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 on kokoelma avoimen lähdekoodin yrityssovelluksia, jotka kattavat kaikki yrityksesi tarpeet: asiakkuudenhallinta eli CRM, verkkokauppa, kirjanpito, varastointi, kassajärjestelmä, projektinhallinta, jne.

Odoon uniikki arvolupaus on olla samanaikaisesti erittäin helppokäyttöinen ja täysin integroitu.

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