コンテンツへスキップ
Odoo メニュー
  • サインイン
  • 無料で15日試す
  • アプリ
    財務
    • 会計
    • 請求
    • 経費
    • スプレッドシート(BI)
    • ドキュメント管理
    • 署名
    販売
    • CRM
    • 販売
    • POS店舗
    • POSレストラン
    • サブスクリプション
    • レンタル
    ウェブサイト
    • ウェブサイトビルダー
    • eコマース
    • ブログ
    • フォーラム
    • ライブチャット
    • eラーニング
    サプライチェーン
    • 在庫
    • 製造
    • 製品ライフサイクル管理 (PLM)
    • 購買
    • 整備
    • 品質
    人事業務
    • 従業員管理
    • 採用
    • 休暇管理
    • 人事評価
    • リファラル
    • フリート
    マーケティング
    • ソーシャルマーケティング
    • メールマーケティング
    • SMSマーケティング
    • イベント
    • マーケティングオートメーション
    • アンケート調査
    サービス
    • プロジェクト管理
    • タイムシート
    • フィールドサービス
    • ヘルプデスク
    • 計画
    • アポイントメント
    生産性向上ツール
    • ディスカッション
    • 承認
    • IoT
    • VoIP
    • ナレッジ
    • WhatsApp
    サードパーティアプリ Odooスタジオ Odooクラウドプラットホーム
  • インダストリー(業種別ソリューション)
    小売
    • 書店
    • アパレルショップ
    • 家具専門店
    • 食料品店
    • 金物店
    • 玩具店
    飲食・ホスピタリティ業界
    • バー・パブ
    • レストラン
    • ファストフード
    • ゲストハウス
    • 飲料販売代理店
    • ホテル
    不動産
    • 不動産会社
    • 建築事務所
    • 建設
    • 不動産管理
    • 造園
    • 住宅所有者組合
    コンサルティング
    • 会計事務所
    • Odooパートナー
    • マーケティングエージェンシー
    • 法律事務所
    • 人材派遣
    • 監査・認証
    製造
    • テキスタイル
    • 金属
    • 家具
    • 飲食
    • 醸造所
    • コーポレートギフト
    ヘルス & フィットネス
    • スポーツクラブ
    • 眼鏡店
    • フィットネスセンター
    • ウェルネス専門家
    • 薬局
    • ヘアサロン
    業種
    • 便利屋
    • IT ハードウェア・サポート
    • 太陽エネルギーシステム
    • 靴メーカー
    • クリーニングサービス
    • 空調設備サービス
    その他
    • 非営利団体
    • 環境機関
    • ビルボードレンタル
    • 写真
    • 自転車リース
    • ソフトウェアリセラー
    すべての業種を見る
  • コミュニティ
    学ぶ
    • チュートリアル
    • ドキュメンテーション
    • 認定
    • トレーニング
    • ブログ
    • ポッドキャスト
    教育サポート
    • 教育プログラム
    • Scale Up! ビジネスゲーム
    • Odooオフィス訪問
    ソフトを入手
    • ダウンロード
    • エディションを比較
    • リリース
    コラボレーション
    • Github
    • フォーラム
    • イベント
    • 翻訳
    • パートナーになる
    • パートナー様向けサービス
    • 会計事務所を登録
    サービス利用
    • パートナー一覧
    • 会計事務所一覧
    • 今すぐ相談する
    • 導入支援サービス
    • お客様一覧
    • サポート
    • アップグレード
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    製品デモを利用する
  • 料金
  • ヘルプ

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

  • CRM
  • e-Commerce
  • 会計
  • 在庫
  • PoS
  • プロジェクト
  • MRP
All apps
コミュニティで交流するには登録する必要があります。
全てのポスト 人々 バッジ
タグ (全て表示)
odoo accounting v14 pos v15
このフォーラムについて
コミュニティで交流するには登録する必要があります。
全てのポスト 人々 バッジ
タグ (全て表示)
odoo accounting v14 pos v15
このフォーラムについて
ヘルプ

SQL Querry for Dynamic View

購読

この投稿に活動があった際に通知を受け取ります

この質問にフラグが付けられました
querysqldynamicmodelodoo16features
1 返信
3044 ビュー
アバター
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
アバター
破棄
アバター
Hans Rickhoff 🚀 https://obd.digital
最善の回答

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
アバター
破棄
ディスカッションを楽しんでいますか?読むだけでなく、参加しましょう!

今すぐアカウントを作成して、限定機能を利用したり、素晴らしいコミュニティと交流しましょう!

登録
関連投稿 返信 ビュー 活動
Moving accessory products to alternative products
sql odoo16features
アバター
0
4月 24
1271
How to solved this SQL error ?? 解決済
query sql
アバター
アバター
1
9月 21
3824
How to print tree_view from sql query in odoo 11
query sql tree_view
アバター
0
10月 21
1691
[Odoo16] ERROR: could not serialize access due to concurrent update
community error query odoo16features
アバター
1
9月 24
3210
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
アバター
アバター
1
4月 24
2476
コミュニティ
  • チュートリアル
  • ドキュメンテーション
  • フォーラム
オープンソース
  • ダウンロード
  • Github
  • Runbot
  • 翻訳
サービス
  • Odoo.shホスティング
  • サポート
  • アップグレード
  • カスタム開発
  • 教育プログラム
  • 会計事務所一覧
  • パートナー一覧
  • パートナーになる
企業情報
  • 会社概要
  • ブランドアセット
  • お問い合わせ
  • 採用情報
  • イベント
  • ポッドキャスト
  • ブログ
  • お客様一覧
  • リーガル情報 • プライバシーポリシー
  • セキュリティ
الْعَرَبيّة 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(オドゥー)は、CRM、eコマース、会計、在庫管理、POS、プロジェクト管理など、企業のさまざまな業務を一つのシステムで管理できる、ベルギー発のオープンソースのERPソフトウェアです。

高機能で使いやすく、完全に統合されたERPとして、ユニークな価値を提供しています。

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