Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Managament
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Help

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

How to _inherit properly?

Odoberať

Get notified when there's activity on this post

This question has been flagged
purchaseinheritpurchase_order_inherits
4 Replies
8008 Zobrazenia
Avatar
Ashok Kumar Sahoo

I am modifying Purchase module to add a new field in purchase order lines. I have successfully added the code to create model and view the custom field. But unable to add the custom field to total amount of the P.O. line.

class customPo(object):

    _inherit="purchase.order"
    _name = 'customPo'

    def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
        res = {}
        cur_obj=self.pool.get('res.currency')
        for order in self.browse(cr, uid, ids, context=context):
            res[order.id] = {
                'amount_untaxed': 0.0,
                'amount_tax': 0.0,
                'amount_total': 0.0,
            }
            val = val1 = 0.0
            cur = order.pricelist_id.currency_id
            for line in order.order_line:
               # val1 += line.price_subtotal
               val1 = val1 + line.data + line.price_subtotal
               for c in self.pool.get('account.tax').compute_all(cr, uid, line.taxes_id, line.price_unit, line.product_qty, line.product_id, order.partner_id)['taxes']:
                    val += c.get('amount', 0.0)
            res[order.id]['amount_tax']=cur_obj.round(cr, uid, cur, 42.0)
            res[order.id]['amount_untaxed']=cur_obj.round(cr, uid, cur, val1)
            res[order.id]['amount_total']=res[order.id]['amount_untaxed'] + res[order.id]['amount_tax']
        return res

        _columns = {
            'order_line': fields.one2many('purchase.order.line', 'order_id', 'Order Lines', states={'approved':[('readonly',True)],'done':[('readonly',True)]}),
            'amount_untaxed': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Untaxed Amount',
                store={
                    'purchase.order.line': (_get_order, None, 10),
                }, multi="sums", help="The amount without tax", track_visibility='always'),
            'amount_tax': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Taxes',
                store={
                    'purchase.order.line': (_get_order, None, 10),
                }, multi="sums", help="The tax amount"),
            'amount_total': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Total',
                store={
                    'purchase.order.line': (_get_order, None, 10),
                }, multi="sums",help="The total amount"),
        }
customPo()

class customPol(osv.osv):
    _inherit = 'purchase.order.line'
    # _name = 'something.notpurchase'
    _columns = {
        'data': fields.float('Unit Price', required=True, digits_compute= dp.get_precision('Product Price')),
    }

customPol()

I have kept the tax static as 42 so, I can know when the overridden method is called but it never happens.

My view file is the following.

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
        <record id="custom_purchse_wa" model="ir.ui.view">
            <field name="name">Custom Field New</field>
            <field name="model">purchase.order</field>
            <field name="inherit_id" ref="purchase.purchase_order_form"/>
            <field name="arch" type="xml">
                <xpath expr="/form/sheet/notebook/page/field[@name='order_line']/tree/field[@name='price_unit']" position="after">
                <field name="data" string="Custom field"/>
                </xpath>
            </field>
        </record>
</data>
</openerp>
1
Avatar
Zrušiť
David Brilliant

Ok, just some general things that need to be changed here: First of all _columns looks like its under the indentation of your _ammount_all function. this needs to be in the scope of the object, not the function. Its good form to declare these at the beginning of your class.

Avatar
Simplify it!
Best Answer

Change this:

class customPo(object):

_inherit="purchase.order"
_name = 'customPo'

And do this:

class customPo(osv.osv):

_inherit="purchase.order"
#_name = 'customPo'
1
Avatar
Zrušiť
Ashok Kumar Sahoo
Autor

wow I missed osv.osv! but after this edit it doesnt work, still the method from purchase.py is being called not my custom code.

David Brilliant

Ashok, how were you expecting the method to be called? Is this an override of an existing method? or is it called on change of some field?

Ashok Kumar Sahoo
Autor

it is override of existing method in purchase module. it is being called by the view <field name="model">purchase.order</field>

Avatar
Ashok Kumar Sahoo
Autor Best Answer

The _columns was indented to be inside the method which didnt made any columns therby breaking the method, fixed the indentation add one more dependent method and it worked.

0
Avatar
Zrušiť
Avatar
Mohamed Habib Challouf
Best Answer
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
        <record id="custom_purchse_wa" model="ir.ui.view">
            <field name="name">Custom Field New</field>
            <field name="model">purchase.order</field>
            <field name="inherit_id" ref="purchase.purchase_order_form"/>
            <field name="arch" type="xml">
                <xpath expr="/form/sheet/notebook/page/field/tree[@string='Purchase Order Lines']/field[@name='price_unit']" position="after">
                <field name="data" string="Custom field"/>
            </xpath>
        </field>
    </record>

</data> </openerp>

0
Avatar
Zrušiť
Ashok Kumar Sahoo
Autor

still not working, in fact no changes at all..

AJ Schrafel Paper Corp

ddi you run "update module" from the settings menu for your module?

Ashok Kumar Sahoo
Autor

issue solved, the _columns was indented inside of the function and the fuction :/

Avatar
Ashif Abdulrahman
Best Answer

use this

class purchase_order_line(osv.osv):
    _inherit = 'purchase.order.line'
    _columns = {
        'data': fields.float('Unit Price', required=True, digits_compute= dp.get_precision('Product Price')),
    }

purchase_order_line()

and add this in xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
        <record id="custom_purchse_module_inherit" model="ir.ui.view">
            <field name="name">purchase.order.form</field>
            <field name="model">purchase.order</field>
            <field name="inherit_id" ref="purchase.purchase_order_form"/>
            <field name="arch" type="xml">
                <xpath expr="/form/sheet/notebook/page/field[@name='order_line']/tree[@string='Purchase Order Lines']/field[@name='price_unit']" position="after">
                <field name="data" string="Custom field"/>
            </xpath>
        </field>
    </record>

</data> </openerp>
0
Avatar
Zrušiť
Ashok Kumar Sahoo
Autor

Do you think changing names and ids will work?

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

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

Registrácia
Related Posts Replies Zobrazenia Aktivita
edit due date after creating partial purchase order
purchase purchase_order
Avatar
0
máj 22
3327
Purchase prototype products; What´s your solution?
purchase purchase_order
Avatar
0
júl 24
2434
How to enable Source Document (field label) Origin (field name) Solved
purchase purchase_order
Avatar
Avatar
1
nov 20
5165
Configuring Purchase Order Form and Report Solved
purchase purchase_order
Avatar
Avatar
1
okt 20
5661
Show product default code in purchase order line Solved
purchase purchase_order
Avatar
Avatar
Avatar
Avatar
3
apr 18
7964
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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