Skip to Content
Odoo เมนู
  • ลงชื่อเข้าใช้
  • ทดลองใช้ฟรี
  • แอป
    การเงิน
    • ระบบบัญชี
    • ระบบการออกใบแจ้งหนี้
    • ระบบบัญชีรายจ่าย
    • ระบบการจัดการข้อมูลผ่านสเปรดชีต (BI)
    • เอกสาร
    • ระบบลงลายเซ็น
    การขาย
    • ลูกค้าสัมพันธ์
    • การขาย
    • POS ร้านค้า
    • POS ร้านอาหาร
    • ระบบสมัครสมาชิก
    • การเช่า
    การจัดการเว็บไซต์
    • เครื่องมือสร้างเว็บไซต์
    • ระบบการขายออนไลน์
    • บล็อก
    • ฟอรั่ม
    • ไลฟ์แชท
    • ระบบการอบรมออนไลน์
    ซัพพลายเชน
    • คลังสินค้า
    • ระบบการผลิต
    • PLM
    • ระบบการจัดซื้อ
    • การซ่อมบำรุง
    • ระบบจัดการคุณภาพ
    ทรัพยากรบุคคล
    • ข้อมูลพนักงาน
    • ระบบสรรหาบุคลากร
    • ระบบการลา
    • การประเมิน
    • ระบบการแนะนำพนักงาน
    • ระบบจัดการยานพาหนะ
    การตลาด
    • โซเชียลมาร์เก็ตติ้ง
    • การตลาดผ่านอีเมล
    • ระบบการตลาดผ่าน SMS
    • ระบบการจัดงานอีเวนต์
    • การตลาดแบบอัตโนมัติ
    • ระบบแบบสำรวจ
    การบริการ
    • โปรเจกต์
    • ระบบบันทึกเวลา
    • ระบบการจัดการบริการภาคสนาม
    • ระบบดูแลช่วยเหลือ
    • การวางแผน
    • การนัดหมาย
    ประสิทธิผล
    • ระบบแสดงความคิดเห็น
    • ระบบการอนุมัติ
    • ไอโอที
    • VoIP
    • คลังข้อมูล
    • WhatsApp
    แอปพลิเคชันของบุคคลที่สาม Odoo สตูดิโอ แพลตฟอร์มคลาวด์ของ Odoo
  • อุตสาหกรรม
    การค้าปลีก
    • ร้านขายหนังสือ
    • ร้านขายเสื้อผ้า
    • ร้านขายเฟอร์นิเจอร์
    • ร้านขายของชำ
    • ร้านขายฮาร์ดแวร์
    • ร้านขายของเล่น
    Food & Hospitality
    • บาร์และผับ
    • ร้านอาหาร
    • อาหารฟาสต์ฟู้ด
    • Guest House
    • ตัวแทนจำหน่ายเครื่องดื่ม
    • Hotel
    อสังหาริมทรัพย์
    • Real Estate Agency
    • บริษัทสถาปัตยกรรม
    • บริษัทรับเหมา
    • การจัดการอสังหาริมทรัพย์
    • การจัดสวน
    • สมาคมเจ้าของอสังหาริมทรัพย์
    ปรึกษา
    • สำนักงานบัญชี
    • Odoo พาร์ทเนอร์
    • เอเจนซี่การตลาด
    • สำนักงานกฎหมาย
    • บริการสรรหาบุคลากร
    • การตรวจสอบและการรับรอง
    ระบบการผลิต
    • Textile
    • เหล็ก
    • เฟอร์นิเจอร์
    • อาหาร
    • Brewery
    • ของขวัญขององค์กร
    สุขภาพ & ฟิตเนส
    • ชมรมกีฬา
    • ร้านขายแว่นตา
    • ฟิตเนส
    • ผู้ประกอบวิชาชีพด้านสุขภาพ
    • ร้านขายยา
    • ร้านทำผม
    Trades
    • ช่างซ่อม
    • ฮาร์ดแวร์และการสนับสนุนด้านไอที
    • ระบบพลังงานแสงอาทิตย์
    • ช่างทำรองเท้า
    • บริการทำความสะอาด
    • HVAC Services
    อื่น ๆ
    • Nonprofit Organization
    • สำนักงานสิ่งแวดล้อม
    • ร้านเช่าป้ายโฆษณา
    • การถ่ายภาพ
    • ร้านเช่าจักรยาน
    • ตัวแทนจำหน่ายซอฟต์แวร์
    Browse all Industries
  • คอมมูนิตี้
    ศึกษา
    • บทเรียน
    • เอกสารกำกับโปรแกรม
    • การรับรอง
    • การฝึกอบรม
    • บล็อก
    • พอดแคสต์
    เพิ่มศักยภาพให้กับการศึกษา
    • โปรแกรมการศึกษา
    • Scale Up! Business Game
    • เยี่ยมชม Odoo
    รับซอฟต์แวร์
    • ดาวน์โหลด
    • เปรียบเทียบรุ่น
    • เผยแพร่
    ทำงานร่วมกัน
    • Github
    • ฟอรั่ม
    • ระบบการจัดงานอีเวนต์
    • การแปล
    • ร่วมเป็นพาร์ทเนอร์
    • Services for Partners
    • ลงทะเบียนเพื่อสร้างบัญชีบริษัทของคุณ
    รับบริการ
    • ค้นหาพาร์ทเนอร์
    • ค้นหานักบัญชี
    • พบกับที่ปรึกษา
    • บริการติดตั้งระบบเพื่อใช้งาน
    • ข้อมูลอ้างอิงลูกค้า
    • การสนับสนุน
    • อัปเกรด
    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:

  • ลูกค้าสัมพันธ์
  • e-Commerce
  • ระบบบัญชี
  • สินค้าคงคลัง
  • PoS
  • โปรเจกต์
  • MRP
All apps
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
All Posts คน เหรียญรางวัล
แท็ก (View all)
odoo accounting v14 pos v15
เกี่ยวกับฟอรั่มนี้
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
All Posts คน เหรียญรางวัล
แท็ก (View all)
odoo accounting v14 pos v15
เกี่ยวกับฟอรั่มนี้
ช่วยเหลือ

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

ติดตาม

รับการแจ้งเตือนเมื่อมีกิจกรรมในโพสต์นี้

คำถามนี้ถูกตั้งค่าสถานะ
13119 มุมมอง
อวตาร
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
อวตาร
ละทิ้ง
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
ผู้เขียน

ok, title changed!!

สนุกกับการพูดคุยนี้ใช่ไหม? เข้าร่วมเลย!

สร้างบัญชีวันนี้เพื่อเพลิดเพลินไปกับฟีเจอร์พิเศษและมีส่วนร่วมกับคอมมูนิตี้ที่ยอดเยี่ยมของเรา!

ลงชื่อ
คอมมูนิตี้
  • บทเรียน
  • เอกสารกำกับโปรแกรม
  • ฟอรั่ม
โอเพนซอร์ส
  • ดาวน์โหลด
  • 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 eCommerce ระบบบัญชี ระบบสินค้าคงคลัง ระบบการขายหน้าร้าน โปรเจกต์ และ อีกมากมาย

ความเหนือกว่าอันเป็นเอกลักษณ์ของ 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