Skip ke Konten
Odoo Menu
  • Login
  • Uji coba gratis
  • Aplikasi
    Keuangan
    • Akuntansi
    • Faktur
    • Pengeluaran
    • Spreadsheet (BI)
    • Dokumen
    • Tanda Tangan
    Sales
    • CRM
    • Sales
    • POS Toko
    • POS Restoran
    • Langganan
    • Rental
    Website
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Rantai Pasokan
    • Inventaris
    • Manufaktur
    • PLM
    • Purchase
    • Maintenance
    • Kualitas
    Sumber Daya Manusia
    • Karyawan
    • Rekrutmen
    • Cuti
    • Appraisal
    • Referensi
    • Armada
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Acara
    • Otomatisasi Marketing
    • Survei
    Layanan
    • Project
    • Timesheet
    • Layanan Lapangan
    • Meja Bantuan
    • Planning
    • Appointment
    Produktivitas
    • Diskusi
    • Approval
    • IoT
    • VoIP
    • Pengetahuan
    • WhatsApp
    Aplikasi pihak ketiga Odoo Studio Platform Odoo Cloud
  • Industri-Industri
    Retail
    • Toko Buku
    • Toko Baju
    • Toko Furnitur
    • Toko Kelontong
    • Toko Hardware
    • Toko Mainan
    Makanan & Hospitality
    • Bar dan Pub
    • Restoran
    • Fast Food
    • Rumah Tamu
    • Distributor Minuman
    • Hotel
    Real Estate
    • Agensi Real Estate
    • Firma Arsitektur
    • Konstruksi
    • Estate Management
    • Perkebunan
    • Asosiasi Pemilik Properti
    Konsultansi
    • Firma Akuntansi
    • Mitra Odoo
    • Agensi Marketing
    • Firma huku
    • Talent Acquisition
    • Audit & Sertifikasi
    Manufaktur
    • Tekstil
    • Logam
    • Perabotan
    • Makanan
    • Brewery
    • Corporate Gift
    Kesehatan & Fitness
    • Sports Club
    • Toko Kacamata
    • Fitness Center
    • Wellness Practitioners
    • Farmasi
    • Salon Rambut
    Perdagangan
    • Handyman
    • IT Hardware & Support
    • Sistem-Sistem Energi Surya
    • Pembuat Sepatu
    • Cleaning Service
    • Layanan HVAC
    Lainnya
    • Organisasi Nirlaba
    • Agen Lingkungan
    • Rental Billboard
    • Fotografi
    • Penyewaan Sepeda
    • Reseller Software
    Browse semua Industri
  • Komunitas
    Belajar
    • Tutorial-tutorial
    • Dokumentasi
    • Sertifikasi
    • Pelatihan
    • Blog
    • Podcast
    Empower Education
    • Program Edukasi
    • Game Bisnis 'Scale Up!'
    • Kunjungi Odoo
    Dapatkan Softwarenya
    • Download
    • Bandingkan Edisi
    • Daftar Rilis
    Kolaborasi
    • Github
    • Forum
    • Acara
    • Terjemahan
    • Menjadi Partner
    • Layanan untuk Partner
    • Daftarkan perusahaan Akuntansi Anda.
    Dapatkan Layanan
    • Temukan Mitra
    • Temukan Akuntan
    • Temui penasihat
    • Layanan Implementasi
    • Referensi Pelanggan
    • Bantuan
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dapatkan demo
  • Harga
  • Bantuan

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

  • CRM
  • e-Commerce
  • Akuntansi
  • Inventaris
  • PoS
  • Project
  • MRP
All apps
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Help

"AttributeError: 'tuple' object has no attribute 'items'" when modifying sale order line via custom code

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
13127 Tampilan
Avatar
Diego Calzadilla

Hello everybody

I have this issue, I have different product categories, let's say cat1, cat2, cat3, and for each of these categories I have defined 2 new fields: "halfcontop" and "highcontop", what they do is to estblish 2 product quantities for getting special price. Now, all my products belong to one of the previous categories and each of my products also have two fields : "prhalfc" and "prhighc" which are my special prices for each product. Now, comes the interesting thing: these prices are reachable depending on the quantity of products by category, and not by the quantity of items of this product , for example, let's think that for cat1, highcontop=10 and I have 11 different products belonging to this category so that if I buy only one of each of these products Im gonna have 11 products and then Im gonna reach "prhighc" for each product which may be different for all products.

I have analyzed the problem and I think that what I should do is to browse the whole sale order, so that I can count the number of products by category, and then, according to this number establish the new prices if necessary.

I also took a deep look at pricelist module, but it doesn't fit my neccesity because it changes the product prices for each line, and what I need to do first is the check the whole sale order.

I have done the following points. But I stiil need some help. Thanks in advace for suggestions!!

This is the code for new fields, everything is fine here:

PY:

from openerp import netsvc from openerp import pooler from openerp.osv import fields, osv, orm from openerp.tools.translate import _

class product_otherprices_inherit(osv.osv): _inherit = 'product.product' _name='product.product' _columns = { 'prhalfc' : fields.float('Price for half consume', help='Enter the price defined for half consume'), 'prhighc' : fields.float('Price for high consume', help='Enter the price defined for high consume'), } class category_price_range_inherit(osv.osv): _inherit = 'product.category' _name = 'product.category' _description = 'Ranges for category prices half & high consume' _columns = { 'halfcontop':fields.float('Range top for half consume',help='Top for half consume'), 'highcontop':fields.float('Range top for high consume',help='Top for high consume'), }

XML:

<openerp> <data> <record model="ir.ui.view" id="product_otherprices_inherit"> <field name="name">product.otherprices.inherit</field> <field name="model">product.product</field> <field name="inherit_id" ref="product.product_normal_form_view"/> <field name="arch" type="xml"> <notebook position="inside"> <page string="Other_Prices"> <group> <field name="prhalfc"/> <field name="prhighc"/> </group> </page> </notebook> </field> </record> </data> </openerp>

<openerp> <data>

    <record model="ir.ui.view" id="category_price_range_inherit">
        <field name="name">product.category.pricerange.inherit</field>
        <field name="model">product.category</field>
        <field name="type">form</field>
        <field name="inherit_id" ref="product.product_category_form_view"/>
        <field name="arch" type="xml"> 

            <sheet> 
                <group> 
                    <group name="parent" col="4"> 
                        <field name="lowcontop" /> 
                        <field name="halfcontop"/> 
                        <field name="highcontop"/> 
                    </group> 
                </group> 
            </sheet>
        </field>
    </record>
</data>

</openerp>

Now, comes the method supossed to change the prices, but it stiil doesn't work

class sale_order_line(osv.osv):

_inherits = 'sale.order.line', 'product.product', 'product.category'
_name="sale.order.line"

def _category_amount_line(self, cr, uid, ids, field_name, arg, context=None):
    tax_obj = self.pool.get('account.tax')
    cur_obj = self.pool.get('res.currency')
    res = []
    if context is None:
        context = {}
    for line in self.browse(cr, uid, ids, context=context): #Lo que intento es que haga referencia a los campos puestos e las clases anteriores, segun entendi, esta funcion compute_all, lo unico que hace es un redondeo con los decimales.
        taxes = tax_obj.compute_all(cr, uid, line.tax_id, line.prhalfc, line.prhighc, line.product_uom_qty, line.order_id.partner_invoice_id.id, line.product_id, line.order_id.partner_id)
        cur = line.order_id.pricelist_id.currency_id
        res[line.id] = cur_obj.round(cr, uid, cur, taxes['total'])
    return res




def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
        uom=False, qty_uos=0, uos=False, name='', partner_id=False,
        lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False, halfcontop=0, highcontop=0, prhalfc=0, prhighc=0, context=None):

    res=[]
    res =  super(sale_order_line, self).product_id_change(
        cr, uid, ids, pricelist, product, qty,
        uom, qty_uos, uos, name, partner_id,
        lang, update_tax, date_order, packaging, fiscal_position, flag, halfcontop, highcontop, prhalfc, prhighc, context=context)
    cat_ids=[]
    for product in product.browse(cr, uid, uid):
        if product.categ_id.id not in cat_ids:
            cat_ids.append(product.categ_id.id)
    cats = pool.get('product.category').name_get(self.cr, self.uid, cat_ids, context=self.localcontext)        
    #Segun yo , hasta esta parte, hemos conseguido las categorias, me base en product_pricelist.py(funcion _get_categories)
    for cat in cats:
        x=0.0
        for product in product.browse(cr, uid, ids):
            if cat == product.product.category_id :
                 x = product.product_uom_qty  + x   #product.qty
        for product in product.browse(cr, uid, ids): 
            if cat == product.product.category_id:

                if x >= product.category.halfcontop and  x < product.category.highcontop :

                    res['price_unit'] = product.prhalfc

                elif x >= product.category.highcontop :

                    res['price_unit'] = product.prhighc

                else :

                    res['price_unit'] = product.price_unit  
    return res

and now the XML, with onchange method:

XML:

<openerp> <data> <record id="view_sale_order_form_minimalprice_form" model="ir.ui.view"> <field name="name">sale.order.form - minimal price</field> <field name="model">sale.order</field> <field name="type">form</field> <field name="priority" eval="20"/> <field name="inherit_id" ref="sale.view_order_form"/> <field name="arch" type="xml"> <data> <xpath expr="//field[@name='price_unit']" position="attributes"> <attribute name="on_change">product_id_change(parent.pricelist_id, product_id, product_uom_qty, product_uom, product_uos_qty, product_uos, name, parent.partner_id, False, True, parent.date_order, False, parent.fiscal_position, False, halfcontop, highcontop, prhalfc, prhighc, context)</attribute> </xpath> </data> </field> </record> </data> </openerp>

and fnally, whe trying to install it,, I get the following error:

Server Traceback (most recent call last): File "/opt/openerp/server/openerp/addons/web/session.py", line 89, in send return openerp.netsvc.dispatch_rpc(service_name, method, args) File "/opt/openerp/server/openerp/netsvc.py", line 292, in dispatch_rpc result = ExportService.getService(service_name).dispatch(method, params) File "/opt/openerp/server/openerp/service/web_services.py", line 626, in dispatch res = fn(db, uid, params) File "/opt/openerp/server/openerp/osv/osv.py", line 188, in execute_kw return self.execute(db, uid, obj, method, *args, *kw or {}) File "/opt/openerp/server/openerp/osv/osv.py", line 131, in wrapper return f(self, dbname, args, *kwargs) File "/opt/openerp/server/openerp/osv/osv.py", line 197, in execute res = self.execute_cr(cr, uid, obj, method, args, *kw) File "/opt/openerp/server/openerp/osv/osv.py", line 185, in execute_cr return getattr(object, method)(cr, uid, args, *kw) File "/opt/openerp/server/openerp/addons/base/module/module.py", line 424, in button_immediate_install return self._button_immediate_function(cr, uid, ids, self.button_install, context=context) File "/opt/openerp/server/openerp/addons/base/module/module.py", line 475, in _button_immediate_function _, pool = pooler.restart_pool(cr.dbname, update_module=True) File "/opt/openerp/server/openerp/pooler.py", line 39, in restart_pool registry = RegistryManager.new(db_name, force_demo, status, update_module) File "/opt/openerp/server/openerp/modules/registry.py", line 218, in new openerp.modules.load_modules(registry.db, force_demo, status, update_module) File "/opt/openerp/server/openerp/modules/loading.py", line 345, in load_modules processed = load_marked_modules(cr, graph, states_to_load, force, status, report, loaded_modules, update_module) File "/opt/openerp/server/openerp/modules/loading.py", line 256, in load_marked_modules loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks) File "/opt/openerp/server/openerp/modules/loading.py", line 161, in load_module_graph models = pool.load(cr, package) File "/opt/openerp/server/openerp/modules/registry.py", line 118, in load model = cls.create_instance(self, cr) File "/opt/openerp/server/openerp/osv/orm.py", line 926, in create_instance obj.__init__(pool, cr) File "/opt/openerp/server/openerp/osv/orm.py", line 1061, in __init__ self._inherits_check() File "/opt/openerp/server/openerp/osv/orm.py", line 3446, in _inherits_check for table, field_name in self._inherits.items(): AttributeError: 'tuple' object has no attribute 'items'

Thanks in adavnce for suggestions!!

1
Avatar
Buang
Andreas Marpmann

"How can I fix this problem?" say nothing! Please enter a short description in headline and add tags.

Ray Carnes

Please review http://help.openerp.com/question/25620/meta-why-do-some-questions-get-answers-and-others-dont/

Diego Calzadilla
Penulis

ok, title changed!!

Menikmati diskusi? Jangan hanya membaca, ikuti!

Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!

Daftar
Komunitas
  • Tutorial-tutorial
  • Dokumentasi
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Terjemahan
Layanan
  • Odoo.sh Hosting
  • Bantuan
  • Peningkatan
  • Custom Development
  • Pendidikan
  • Temukan Akuntan
  • Temukan Mitra
  • Menjadi Partner
Tentang Kami
  • Perusahaan kami
  • Aset Merek
  • Hubungi kami
  • Tugas
  • Acara
  • Podcast
  • Blog
  • Pelanggan
  • Hukum • Privasi
  • Keamanan
الْعَرَبيّة 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 adalah rangkaian aplikasi bisnis open source yang mencakup semua kebutuhan perusahaan Anda: CRM, eCommerce, akuntansi, inventaris, point of sale, manajemen project, dan seterusnya.

Mudah digunakan dan terintegrasi penuh pada saat yang sama adalah value proposition unik Odoo.

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