Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

How to use Create Function in Custom Module [SOLVED]

Subscriure's

Get notified when there's activity on this post

This question has been flagged
2 Respostes
11554 Vistes
Avatar
Ajeng Shilvie

Anyone please help me,

i have a custom module related to purchase.order ,  i use this code to make additional tab in purchase.order here's the code :

approval.py

#I make this new form to save master data approval

class master(osv.osv):
    _name="wtc.approval.matrixbiaya"
    _columns = {
        'form':fields.many2one('ir.model',string='Form',required=True),
        'cabang_id':fields.many2one('res.partner',string='Branch',required=True),
        'divisi_id':fields.selection([('t','Unit'),('s','Sparepart'),('u','Umum'),('f','Finance')],'Division',change_default=True,required=True),
        'group_id':fields.many2one('res.groups',string='Group',required=True),
        'limit': fields.float(digits=(8,2), string="Limit",required=True),
}

#i make this code to make a new tab called 'Approval' in purchase.order

class approval_po(osv.osv):
    _inherit="purchase.order"
    _columns={
              'app_line': fields.one2many('apps.po','purchase_id',string="Table Approval"),
              }

#this code is method to generate button approval
    def wtc_approval(self, cr, uid, ids, context=None):
        res = super(approval_po, self).wtc_approval(cr, uid, ids, context=context)
        print "dffffffffffffffffffff"
        return res

#  This is create method

    def create(self, cr, uid, vals, context=None):
         vit = self.pool.get("wtc.approval.matrixbiaya").search(cr,uid,[("cabang_id","=",vals["cabang_id"]), ("form","=","purchase.order"), ("divisi_id","=",vals["divisi_id"])])
        data = self.pool.get("wtc.approval.matrixbiaya").browse(cr,uid,vit)
        approval = []
        for x in data :
            approval.append({
                             'group':x.group_id.id,
                             'cabang_id':x.cabang_id.id,
                             'wewenang':x.limit,
                             'sts':'1',                             
                             })
        vals["app_line"] = approval
 
        return super(approval_po, self).create(cr, uid, vals, context=context)

#this code is table for a new tab

class approval_po_line(osv.osv):
    _name="apps.po"
    _columns={
              'purchase_id' :fields.many2one('purchase.order','Purchase'),
              'group':fields.many2one('res.groups','Group', select=True),
              'cabang_id': fields.many2one('res.partner','Branch',select=True),
              'wewenang':fields.char('Wewenang', size=128),
              'sts':fields.selection([('1','NO'),('2','OK')],'Status',change_default=True),
              'pelaksana':fields.many2one('res.users','Pelaksana'),
              'tanggal':fields.datetime('Tanggal'),
              }
    _defaults={
              'sts' : '1'
              }

---------------------------------------------------------------------------------------------------------------------------------------------------------

approval_view.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>  
    <!-- this code for a new form Mater Approval -->
<record model="ir.ui.view" id="master_approval_tree_view">
    <field name="name">master.approval.tree</field>
    <field name="model">wtc.approval.matrixbiaya</field>
    <field name="arch" type="xml">
        <tree string="Approval Matrix Biaya">
            <field name="form"/>
            <field name="cabang_id"/>
            <field name="divisi_id"/>
            <field name="group_id"/>
            <field name="limit"/>
        </tree>
     </field>
</record>
    
<record id="master_approval" model="ir.ui.view">
     <field name="name">master.approval.view</field>
     <field name="model">wtc.approval.matrixbiaya</field>
     <field name="arch" type="xml">
         <form string="Form Approval Matrix Biaya" version="7.0">
             <group>
                 <field name="form" style="width: 25%%"/>
                 <field name="cabang_id" style="width: 30%%"/>
                 <field name="divisi_id" style="width: 10%%"/>
                 <field name="group_id" style="width: 45%%"/>
                 <field name="limit"/>
            </group>
        </form>
        </field>                                                                                                                        
</record>     

<record model="ir.actions.act_window" id="approval_action">
    <field name="name">Matrix Approval Biaya</field>
    <field name="res_model">wtc.approval.matrixbiaya</field>
    <field name="view_type">form</field>
    <field name="view_mode">tree,form</field>
</record>

<!-- This code for a new Tab called 'Approval'-->

<record id="rules_approval_po" model="ir.ui.view">
    <field name="name">master_approval_po_tab</field>
    <field name="model">purchase.order</field>
    <field name="inherit_id" ref="purchase.purchase_order_form"/>
    <field name="arch" type="xml">
    
        <button name="view_picking" position="after">
            <button string="Approval" name="wtc_approval" type="object" class="oe_highlight"/>
        </button>
            <field name="partner_id" position="before">
                <field name="cabang_id"></field>
                <field name="divisi_id" style="width:35%%"></field>
            </field>
            <xpath expr="//page[@string='Deliveries &amp; Invoices']" position="after">
            <page string="Approval">
            <field name="app_line">
            <tree string="Approval" editable="bottom">
                <field name="group" />
                <field name="cabang_id"/>
                <field name="wewenang"/>
                <field name="sts"/>
                <field name="pelaksana"/>
                <field name="tanggal"/>
            </tree>
            </field>
            </page>
            </xpath>
    </field>
</record>

<menuitem id="master_approval_menu" name="Approval Matrix Biaya" parent="base.menu_config"  action="approval_action"/>
                     
     </data>
 </openerp>

 

-----------------------------------------------------------------------------------------------------------------------------------------------------

when i create a new purchase order, the approval line doesn't show any record (that's what i want , and i want it to be read only it means it cannot add an item),

then when i save the current form purchase order , the approval line in Approval tab show some record that refer to Custom Form called 'Master Approval' , i got an error .. please help me

1
Avatar
Descartar
Avatar
Ivan
Best Answer

Ajeng, of course it may show some approval lines.  It is created when the PO is created as you have coded in the approval.py in the create method.

0
Avatar
Descartar
Avatar
Ajeng Shilvie
Autor Best Answer

To Ivan ,

it didn't work , when i hit Save Button , there's an error :

Traceback (most recent call last): File "/home/ajeng/odoo/openerp-8.0/openerp/http.py", line 499, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/home/ajeng/odoo/openerp-8.0/openerp/http.py", line 516, in dispatch result = self._call_function(**self.params) File "/home/ajeng/odoo/openerp-8.0/openerp/http.py", line 282, in _call_function return checked_call(self.db, *args, **kwargs) File "/home/ajeng/odoo/openerp-8.0/openerp/service/model.py", line 113, in wrapper return f(dbname, *args, **kwargs) File "/home/ajeng/odoo/openerp-8.0/openerp/http.py", line 279, in checked_call return self.endpoint(*a, **kw) File "/home/ajeng/odoo/openerp-8.0/openerp/http.py", line 732, in __call__ return self.method(*args, **kw) File "/home/ajeng/odoo/openerp-8.0/openerp/http.py", line 375, in response_wrap response = f(*args, **kw) File "/home/ajeng/odoo/addons/HONDA/web/controllers/main.py", line 944, in call_kw return self._call_kw(model, method, args, kwargs) File "/home/ajeng/odoo/addons/HONDA/web/controllers/main.py", line 936, in _call_kw return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs) File "/home/ajeng/odoo/openerp-8.0/openerp/api.py", line 237, in wrapper return old_api(self, *args, **kwargs) File "/home/ajeng/odoo/addons/HONDA/wtc_approval/approval.py", line 77, in create return super(approval_po, self).create(cr, uid, vals, context=context) File "/home/ajeng/odoo/openerp-8.0/openerp/api.py", line 237, in wrapper return old_api(self, *args, **kwargs) File "/home/ajeng/odoo/addons/HONDA/purchase/purchase.py", line 317, in create order = super(purchase_order, self).create(cr, uid, vals, context=context) File "/home/ajeng/odoo/openerp-8.0/openerp/api.py", line 237, in wrapper return old_api(self, *args, **kwargs) File "/home/ajeng/odoo/addons/HONDA/mail/mail_thread.py", line 377, in create thread_id = super(mail_thread, self).create(cr, uid, values, context=context) File "/home/ajeng/odoo/openerp-8.0/openerp/api.py", line 237, in wrapper return old_api(self, *args, **kwargs) File "/home/ajeng/odoo/openerp-8.0/openerp/api.py", line 332, in old_api result = method(recs, *args, **kwargs) File "/home/ajeng/odoo/openerp-8.0/openerp/models.py", line 3970, in create record = self.browse(self._create(old_vals)) File "/home/ajeng/odoo/openerp-8.0/openerp/api.py", line 235, in wrapper return new_api(self, *args, **kwargs) File "/home/ajeng/odoo/openerp-8.0/openerp/api.py", line 464, in new_api result = method(self._model, cr, uid, *args, **kwargs) File "/home/ajeng/odoo/openerp-8.0/openerp/models.py", line 4148, in _create result += self._columns[field].set(cr, self, id_new, field, vals[field], user, rel_context) or [] File "/home/ajeng/odoo/openerp-8.0/openerp/osv/fields.py", line 699, in set if act[0] == 0: KeyError: 0

do you know how to solve it, please ?

0
Avatar
Descartar
Ivan

It is because for 2many fields (like app_line) you need to specify the value properly in the format that is recognized. Open the odoo/openerp/osv/fields.py file and search for many2many class. Above there is an explanation on what the value should be. In summary, to set the value for 2many field you need to supply a list that contains tuples, e.g. [(0, 0, {fields}), (1, ID1, {fields}), (0, 0, {fields}), (2, ID2)]. The first entry (0, 1, 2, 3, 4, 5, 6) are operations. For each operation they need to have additional information. Read the explanation. Your code should be something like: approval.append((0, 0, {'group':x.group_id.id, 'cabang_id':x.cabang_id.id, 'wewenang':x.limit, 'sts':'1'})

Ajeng Shilvie
Autor

Terimakasih ivan, it works :D

Ivan

Sama sama. You could help others to mark the answer.

Ajeng Shilvie
Autor

Caranya gimana mas, saya kurang karmanya .

Ivan

Banyak banyak sharing dengan yang lain ya, biar bisa naik karmanya.

Ajeng Shilvie
Autor

iya , saya masih ada pertanyaan boleh tidak mas ? cara mengambil user yang login untuk dimasukan kedalam tab approval tadi ketika button approval diklik

Ivan

Karena ini forum internasional, ada baiknya tidak menggunakan Bahasa Indonesia dalam tanya jawab. Dan jika ada pertanyaan lain, tolong di-post sebagai pertanyaan baru. Anyway, you are inquiring how to get the currently logged in user. The currently logged in user's Databae ID is supplied to the create method as the 3rd argument (uid). So, you can directly use that to populate any res.users many2one fields, or if you want to get it's attribute do a self.pool.get('res.users').browse(cr, uid, uid, context=context) to get the browse object.

Ajeng Shilvie
Autor

oke thank you..

Enjoying the discussion? Don't just read, join in!

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

Registrar-se
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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