콘텐츠로 건너뛰기
Odoo 메뉴
  • 로그인
  • 무료 체험하기
  • 앱
    재무 관리
    • 회계
    • 청구서 관리
    • 비용 관리
    • 스프레드시트 (BI)
    • 문서
    • 전자 서명
    판매
    • CRM
    • 판매
    • POS 스토어
    • POS 레스토랑
    • 구독
    • 렌탈
    웹사이트
    • 웹사이트 빌더
    • 이커머스
    • 블로그
    • 포럼
    • 실시간 채팅
    • 온라인 학습 관리
    공급망
    • 재고 관리
    • 제조 관리
    • 제품 수명주기 관리 (PLM)
    • 매입
    • 유지관리
    • 품질
    인적자원 관리
    • 직원
    • 채용
    • 휴가 관리
    • 인사 평가
    • 인재 추천
    • 차량 관리
    마케팅
    • 소셜 마케팅
    • 이메일 마케팅
    • SMS 마케팅
    • 행사
    • 마케팅 자동화
    • 설문 조사
    서비스
    • 프로젝트
    • 작업 기록
    • 현장 서비스
    • 헬프데스크
    • 일정 관리
    • 일정 예약
    생산성
    • 메일 및 채팅
    • 전자 결재
    • IoT
    • VoIP
    • 지식 센터
    • WhatsApp
    타사 앱 Odoo 스튜디오 Odoo 클라우드 플랫폼
  • 인더스트리
    리테일
    • 서점
    • 의류 매장
    • 가구점
    • 식료품점
    • 철물점
    • 장난감 가게
    식음료 & 숙박업
    • 바 & 펍
    • 레스토랑
    • 패스트푸드
    • 게스트 하우스
    • 음료 유통업체
    • 호텔
    부동산
    • 부동산 중개업체
    • 건축 회사
    • 건설
    • 부동산 관리
    • 가드닝
    • 부동산 소유자 협회
    컨설팅
    • 회계 법인
    • Odoo 파트너
    • 마케팅 대행사
    • 법률 사무소
    • 인재 영입
    • 감사 및 인증
    제조 관리
    • 텍스타일
    • 메탈
    • 가구
    • 푸드
    • 양조장
    • 기업용 선물
    건강 & 피트니스
    • 스포츠 클럽
    • 안경점
    • 피트니스 센터
    • 웰니스 전문가
    • 약국
    • 미용실
    사업
    • 핸디맨
    • IT 하드웨어 및 지원 서비스
    • 태양 에너지 시스템
    • 제화업체
    • 클리닝 서비스
    • HVAC 서비스
    기타
    • 비영리 단체
    • 환경 에이전시
    • 광고판 임대
    • 사진
    • 자전거 임대
    • 소프트웨어 리셀러
    전체 인더스트리 찾아보기
  • 커뮤니티
    학습
    • 튜토리얼
    • 문서
    • 인증
    • 훈련
    • 블로그
    • 팟캐스트
    교육 역량 강화
    • 교육 프로그램
    • Scale-Up! 경영관리 게임
    • Odoo에 방문해보세요
    소프트웨어 신청
    • 다운로드
    • 버전 살펴보기
    • 릴리즈 내역
    협업
    • Github
    • 포럼
    • 행사
    • 번역
    • 파트너 등록
    • 파트너 대상 서비스
    • 회계 법인 정보 등록
    서비스 신청
    • 파트너 검색
    • 회계사 검색
    • 전문 상담 예약
    • 구현 서비스
    • 고객 정보
    • 고객 지원
    • 업그레이드
    Github 유튜브 트위터 링크드인 인스타그램 페이스북 스포티파이
    +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 return a tree view from a python function

구독

이 게시물에 활동이 있으면 알림 받기

신고된 질문입니다
10 답글
23148 화면
아바타
MIADI

Hello, I asked on this forum how to put 2 actions for 1 menuitem but someone answers that I don't need to put 2 actions for 1 menuitem but I've to return the tree view in my python function which is called in my action server in my XML file.


This is my python code :

class miadi_poidsConditionnement(models.Model):

    _name = 'miadi.poidsconditionnement'

    # _order = 'conditionnement_id asc'

    conditionnement_id = fields.Many2one('miadi.packaging', 'Packaging', default='', required=True)

    produit_id = fields.Many2one('product.product', 'Product', default='', required=True)

    nb_articles = fields.Integer(string='Number of products', default=0)

    poids = fields.Float(string='Packaging Weight', default=0)

    _sql_constraints = [

    ('uniq_id', 'unique(produit_id, conditionnement_id)', 'A product already exists with this packaging !'),

    ]

    @api.multi

    @api.model

    def chargement_ratio(self):

        productRatio = self.env['miadi.poidsconditionnement']

        conditionnements = self._cr.execute("SELECT id FROM miadi_packaging")

        query_cond = self.env.cr.dictfetchall()

        produits = self._cr.execute("SELECT id FROM product_product")

        query_prod = self.env.cr.dictfetchall()

        for conditionnements in query_cond:

            nom_conditionnement = conditionnements['id']

            for produits in query_prod:

                product = produits['id']

                if_exist = self._cr.execute("SELECT * FROM miadi_poidsConditionnement WHERE conditionnement_id=%s AND produit_id=%s", (nom_conditionnement, product))

                if not if_exist:

                    Ratio = productRatio.create({'conditionnement_id': nom_conditionnement, 'produit_id': product})

                    return {'type': 'ir.actions.act_window', 'view_type': 'tree', 'view_mode': 'tree', 'res_model': 'miadi.poidsconditionnement', 'res_id': miadi.poidsconditionnement.id, 'view_id': self.env.ref('action_miadi_poidsConditionnement').id, 'target': 'current',}


And this is my XML :

<?xml version="1.0" encoding="utf-8"?>

<openerp>

 <data>

  <record id="miadi_poidsConditionnement_form" model="ir.ui.view">

   <field name="name">miadi.poidsconditionnement.form</field>

   <field name="model">miadi.poidsconditionnement</field>

   <field name="arch" type="xml">

    <form string="Weight/number ratio">

     <group col="4">

      <field name="produit_id" widget="selection" eval="ref('product.product.attribute_value_ids')" />

      <!-- <field name="produit_id" /> -->

      <field name="conditionnement_id" widget="selection" eval="ref('miadi.packaging.conditionnement_id')" />

      <!-- <field name="conditionnement_id" /> -->

      <field name="nb_articles" />

      <field name="poids" />

     </group>

    </form>

   </field>

  </record>

  <record id="miadi_poidsConditionnement_tree" model="ir.ui.view">

   <field name="name">miadi.poidsconditionnement.tree</field>

   <field name="model">miadi.poidsconditionnement</field>

   <field name="arch" type="xml">

    <tree string="Weight/number ratio">

     <field name="produit_id" ref="product.product.attribute_value_ids" />

     <field name="conditionnement_id" ref="miadi.packaging.conditionnement_id" />

     <field name="nb_articles" />

     <field name="poids" />

    </tree>

   </field>

  </record>

  <record model="ir.ui.view" id="miadi_poidsConditionnement_search">

   <field name="name">miadi.poidsconditionnement.search</field>

   <field name="model">miadi.poidsconditionnement</field>

   <field name="arch" type="xml">

    <search string="Weight/number ratio">

     <field name="produit_id" />

     <group expand="0" string="Group by">

      <filter string="Product" domain="[]" context="{'group_by':'produit_id'}"/>

      <filter string="Packaging" domain="[]" context="{'group_by':'conditionnement_id'}"/>

     </group>

    </search>

   </field>

  </record>

  <record model="ir.actions.act_window" id="action_miadi_poidsConditionnement">

   <field name="name">Weight/number ratio</field>

   <field name="type">ir.actions.act_window</field>

   <field name="res_model">miadi.poidsconditionnement</field>

   <field name="view_type">form</field>

   <field name="view_mode">tree,form</field>

   <field name="view_id" ref="miadi_poidsConditionnement_tree"/>

   <field name="help" type="html">

    <p class="oe_view_nocontent_create">Click here to create a weight/number ratio.</p>

   </field>

  </record>

  <record id="action_chargement_ratio" model="ir.actions.server">

   <field name="name">Chargement Ratio</field>

   <field name="res_model">action_miadi_poidsConditionnement</field>

   <field name="type">ir.actions.server</field>

   <field name="model_id" ref="model_miadi_poidsconditionnement"/>

   <field name="code">chargementRatio = env['miadi.poidsconditionnement'].browse(context.get('active_id'));chargementRatio.chargement_ratio()</field>

  </record>

  <menuitem name="Weight/number ratio" id="menu_miadi_poidsConditionnement" parent="menu_miadi_packaging" sequence="15" groups="sales_team.group_sale_manager" action="action_chargement_ratio" />

 </data>

</openerp>


And it gives me an issue :

ValueError: <type 'exceptions.NameError'>: "global name 'miadi' is not defined" while evaluating
u"chargementRatio = env['miadi.poidsconditionnement'].browse(context.get('active_id'));chargementRatio.chargement_ratio()"


I want to return the tree view (action_miadi_packaging) and I want my python function is called when I click on the menuitem

How can I resolve this issue ?


And if I write "'res_id': productRatio.id" (where productRatio = self.env['miadi.poidsconditionnement']), instead of "'res_id': miadi.poidsconditionnement.id" the error is :

ValueError: <type 'exceptions.ValueError'>: "need more than 1 value to unpack" while evaluating
u"chargementRatio = env['miadi.poidsconditionnement'].browse(context.get('active_id'));chargementRatio.chargement_ratio()"

Thanks for answers


PS : I'm on Odoo 10

0
아바타
취소
아바타
Niyas Raphy (Walnut Software Solutions)
베스트 답변

Hi Miadi,

You can return a view from python code like this, you have to mention the correct view id

return {
'name': _('test'),
'view_type': 'tree',
'view_mode': 'tree',
'view_id': self.env.ref('account.invoice_tree').id,
'res_model': 'account.invoice',
'context': "{'type':'out_invoice'}",
'type': 'ir.actions.act_window',
'target': 'new',
}
2
아바타
취소
MIADI
작성자

Hi Niyas,

my view_id is correct (if you look my XML code and my Python code, you can see that the view id is correct

MIADI
작성자

I update my code with your answer and it's works, my tree view is display BUT, what I put in my code before the return doesn't happen...

MIADI
작성자

No, finally it doesn't works, it gives me this issue : ValueError: <type 'exceptions.NameError'>: "global name '_' is not defined" while evaluating

u"chargementRatio = env['miadi.poidsconditionnement'];chargementRatio.chargement_ratio()"

MIADI
작성자

and if I remove 'name': _('test'), the view is not display

MIADI
작성자

I wrote this :

return {

'name': _('test'),

'view_type': 'tree',

'view_mode': 'tree',

'view_id': self.env.ref('miadi_packaging.miadi_poidsConditionnement_tree').id,

'res_model': 'miadi.poidsconditionnement',

'type': 'ir.actions.act_window',

'target': 'new',

}

It should work no ?

MIADI
작성자

In the action of the menuitem, I've to put the server action id no ?

If yes, it should work but my tree view is not display...

Can you help me ?

MIADI
작성자

Looking at my codes, can you tell me if my view_id is good ? Because nothing happens when I click on the menu

MIADI
작성자

I fix the problem, the error was in my XLM code

But the result is not really that I want...

When I click on the menuitem, I have a popup^with the tree view but I can't modify the records and what I really want is to have a tree view but not in a popup, I want a "normal" tree view

Niyas Raphy (Walnut Software Solutions)

Hai Miadi, A simplecorrection , not XLM code its XML code

Aslam Up

Hi Niyas,

Can we return this view by some grouping ( A grouped view by state/year/salesperson) ??

joyanto

thanks its work

아바타
MIADI
작성자 베스트 답변

Hi,

It works and I have a treeview but it's not the tree view that I want because I've a tree view in a popup (and I can't chage any record) and what I want is a "normal" tree view

What I have : https://www.hostingpics.net/viewer.php?id=358419Capturetreeview.png


What I want : https://www.hostingpics.net/viewer.php?id=947270Capturetreeview2.png


Or I want to be able to modify some fields in this popup treeview. Is it possible ? If yes, how can I do it ?


If someone can help me, it will be very good

0
아바타
취소
토론이 재미있으신가요? 직접 참여해보세요!

지금 바로 가입하여 독점 서비스를 이용해보고 특별한 커뮤니티와 소통하세요!

가입
커뮤니티
  • 튜토리얼
  • 문서
  • 포럼
오픈 소스
  • 다운로드
  • 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, 이커머스, 회계, 재고, POS, 프로젝트 관리 등 기업의 모든 요구 사항을 충족하도록 설계된 오픈 소스 기반의 통합 비즈니스 앱 제품군입니다.

Odoo의 간편한 UI와 완벽하게 통합된 기능을 직접 확인해 보세요.

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