コンテンツへスキップ
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
このフォーラムについて
ヘルプ

how to create a custom sequence with the format 'company_register-code_reference'?

購読

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

この質問にフラグが付けられました
salesequencecompanyOdoo17
1 返信
1993 ビュー
アバター
Aprilia Zahratunnisa

I want to create a custom sequence. I've tried it but it doesn't work in the 'company_register' section.


This is "company.xml":

            BODEBEK        1           
            Bogor        1           
            Depok        1   
            Bekasi        1   
            Company 2        2                Company 3        3                Company 4        4                Company 5        5                Company 6        6                Company 7        7                Company 8        8                Company 9        9                Company 10        10                Company 11        11                Company 12        12                Company 13        13                Company 14        14                Company 15        15                Company 16        16                Company 17        17       


This is the Company model, so there are 17 companies:

class Company(models.Model)
​_inherit = 'res.company'

​parent_id = fields.Many2one('res.company', string="Parent Company")
​child_ids = fields.One2many('res.company', 'parent_id', string="Branch Companies") 
​company_registry = fields.Char(string="Company Registry", required=True)

​ @api.model
​def create_branch_companies(self):
​ ​parent_company = self.env['res.company'].search([('name', '=', 'BODEBEK')], limit=1)       
​ ​if not parent_company:
​ ​ ​raise ValueError("Parent company 'BODEBEK' not found")
        branch_names = ['Bogor', 'Depok', 'Bekasi']
        for branch_name in branch_names:
​ ​ ​self.env['res.company'].create({
​ ​ ​ ​'name': branch_name,
​ ​ ​ ​'parent_id': parent_company.id,
​ ​ ​ ​'company_registry': '1',
​ ​ ​})
        return True


and this is the Sale Order model where 'reference_code' field resides:

class SaleOrder(models.Model):
​_inherit = 'sale.order'

​reference_code = fields.Char(string="Order Reference", readonly=True, copy=False) 
​company_id = fields.Many2one('res.company', string="Company", required=True)
   
​@api.model   
​def _get_sequence(self, company_id):       
​ ​company = self.env['res.company'].browse(company_id)       
​ ​sequence_code = 'sale.order'       
​ ​sequence = self.env['ir.sequence'].search([
​ ​ ​('code', '=', sequence_code),
​ ​ ​('company_id', '=', company_id)
​ ​])       
​ ​if not sequence:           
​ ​ ​sequence = self.env['ir.sequence'].create({               
​ ​ ​ ​'name': f'Sale Order Reference {company.company_registry}',     
​ ​ ​ ​'code': sequence_code,               
​ ​ ​ ​'company_id': company_id,               
​ ​ ​ ​'prefix': f'{company.company_registry}-',               
​ ​ ​ ​'padding': 5,               
​ ​ ​ ​'number_next': 1,               
​ ​ ​ ​'number_increment': 1,           
​ ​ ​})       
​ ​ ​return sequence

    @api.model   
​def create(self, vals):       
​ ​if vals.get('company_id'):           
​ ​ ​sequence = self._get_sequence(vals['company_id'])
​ ​ ​vals['reference_code'] = f"{sequence.prefix{sequence.next_by_id(sequence.id)}"       
​ ​return super(SaleOrder, self).create(vals)
0
アバター
破棄
Faris Fathurrahman

can you explain better? especially with the 'company.xml' file

アバター
Kanak Infosystems LLP
最善の回答

Greetings, please find the answer to your query below:
 
@api.model    

def create(self, vals):        

    if vals.get('company_id'):            

        sequence = self._get_sequence(vals['company_id'])

        # Generate the next sequence number and update the reference code

        next_sequence_number = sequence.next_by_id( sequence.id )

        vals['reference_code'] = f"{sequence.prefix}{next_sequence_number}"

        # Update the sequence to increment the next number

        sequence.write({'number_next': next_sequence_number + 1})

    return super(SaleOrder, self).create(vals)


 

correct:

vals['reference_code'] = f"{sequence.prefix}{sequence.next_by_id( sequence.id )}"


  • The fix here was to properly concatenate sequence.prefix with the next_by_id( sequence.id ) value, which is the actual next number in the sequence.


  • In your code, the next_by_id() function was being used to generate the reference code, but you weren't updating the number_next field in the sequence record. This would result in the sequence number always remaining the same after the first order.


Your code:

vals['reference_code'] = f"{sequence.prefix}{sequence.next_by_id( sequence.id )}"


The above line just generates the reference code, but does not increment the sequence for the next sale order.


correct:

sequence.write({'number_next': next_sequence_number + 1})


After the reference_code is generated, we need to increment the sequence number. The line above ensures that the number_next field is updated to the next number in the sequence (ie, incremented by 1). This ensures that the sequence number progresses as expected.

We hope this helps! In case you need further assistance- you can reach out to us!

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

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

登録
関連投稿 返信 ビュー 活動
SO new section
sale sequence sale.order.line section V12
アバター
0
9月 20
4291
How to detect if sale order is created from admin or from website? 解決済
sale sequence order backend frontend
アバター
1
10月 15
5499
Displaying Many2one field on mobile devices identical to desktop view in Odoo 17
Odoo17
アバター
アバター
1
7月 25
1778
Issue After Migration: Unable to Save Sales Order in v18 解決済
sale
アバター
アバター
1
5月 25
2054
How to set serial numbers for the sale order line
sale
アバター
アバター
アバター
2
2月 25
11052
コミュニティ
  • チュートリアル
  • ドキュメンテーション
  • フォーラム
オープンソース
  • ダウンロード
  • 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