Skip to Content
Odoo Menu
  • Log ind
  • Prøv gratis
  • Apps
    Økonomi
    • Bogføring
    • Fakturering
    • Udgifter
    • Regneark (BI)
    • Dokumenter
    • e-Signatur
    Salg
    • CRM
    • Salg
    • POS Butik
    • POS Restaurant
    • Abonnementer
    • Udlejning
    Hjemmeside
    • Hjemmesidebygger
    • e-Handel
    • Blog
    • Forum
    • LiveChat
    • e-Læring
    Forsyningskæde
    • Lagerbeholdning
    • Produktion
    • PLM
    • Indkøb
    • Vedligeholdelse
    • Kvalitet
    HR
    • Medarbejdere
    • Rekruttering
    • Fravær
    • Medarbejdersamtaler
    • Anbefalinger
    • Flåde
    Marketing
    • Markedsføring på sociale medier
    • E-mailmarketing
    • SMS-marketing
    • Arrangementer
    • Automatiseret marketing
    • Spørgeundersøgelser
    Tjenester
    • Projekt
    • Timesedler
    • Udkørende Service
    • Kundeservice
    • Planlægning
    • Aftaler
    Produktivitet
    • Dialog
    • Godkendelser
    • IoT
    • VoIP
    • Vidensdeling
    • WhatsApp
    Tredjepartsapps Odoo Studio Odoo Cloud-platform
  • Brancher
    Detailhandel
    • Boghandel
    • Tøjforretning
    • Møbelforretning
    • Dagligvarebutik
    • Byggemarked
    • Legetøjsforretning
    Mad og værtsskab
    • Bar og pub
    • Restaurant
    • Fastfood
    • Gæstehus
    • Drikkevareforhandler
    • Hotel
    Ejendom
    • Ejendomsmægler
    • Arkitektfirma
    • Byggeri
    • Ejendomsadministration
    • Havearbejde
    • Boligejerforening
    Rådgivning
    • Regnskabsfirma
    • Odoo-partner
    • Marketingbureau
    • Advokatfirma
    • Rekruttering
    • Audit & certificering
    Produktion
    • Tekstil
    • Metal
    • Møbler
    • Fødevareproduktion
    • Bryggeri
    • Firmagave
    Heldbred & Fitness
    • Sportsklub
    • Optiker
    • Fitnesscenter
    • Kosmetolog
    • Apotek
    • Frisør
    Håndværk
    • Handyman
    • IT-hardware og support
    • Solenergisystemer
    • Skomager
    • Rengøringsservicer
    • VVS- og ventilationsservice
    Andet
    • Nonprofitorganisation
    • Miljøagentur
    • Udlejning af billboards
    • Fotografi
    • Cykeludlejning
    • Softwareforhandler
    Gennemse alle brancher
  • Community
    Få mere at vide
    • Tutorials
    • Dokumentation
    • Certificeringer
    • Oplæring
    • Blog
    • Podcast
    Bliv klogere
    • Udannelselsesprogram
    • Scale Up!-virksomhedsspillet
    • Besøg Odoo
    Få softwaren
    • Download
    • Sammenlign versioner
    • Udgaver
    Samarbejde
    • Github
    • Forum
    • Arrangementer
    • Oversættelser
    • Bliv partner
    • Tjenester til partnere
    • Registrér dit regnskabsfirma
    Modtag tjenester
    • Find en partner
    • Find en bogholder
    • Kontakt en rådgiver
    • Implementeringstjenester
    • Kundereferencer
    • Support
    • Opgraderinger
    Github Youtube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Få en demo
  • Prissætning
  • Hjælp

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

  • CRM
  • e-Commerce
  • Bogføring
  • Lager
  • PoS
  • Projekt
  • MRP
All apps
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Hjælp

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

Tilmeld

Få besked, når der er aktivitet på dette indlæg

Dette spørgsmål er blevet anmeldt
13120 Visninger
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
Kassér
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
Forfatter

ok, title changed!!

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

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

Tilmeld dig
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Oversættelser
Tjenester
  • Odoo.sh-hosting
  • Support
  • Opgradere
  • Individuelt tilpasset udvikling
  • Uddannelse
  • Find en bogholder
  • Find en partner
  • Bliv partner
Om os
  • Vores virksomhed
  • Brandaktiver
  • Kontakt os
  • Stillinger
  • Arrangementer
  • Podcast
  • Blog
  • Kunder
  • Juridiske dokumenter • Privatlivspolitik
  • Sikkerhedspolitik
الْعَرَبيّة 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 er en samling open source-forretningsapps, der dækker alle dine virksomhedsbehov – lige fra CRM, e-handel og bogføring til lagerstyring, POS, projektledelse og meget mere.

Det unikke ved Odoo er, at systemet både er brugervenligt og fuldt integreret.

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