Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

ir.attachment res_*-fields NULL on save

Naroči se

Get notified when there's activity on this post

This question has been flagged
ir.attachmentcustommoduleodoo12
1 Odgovori
7034 Prikazi
Avatar
Christoph Farnleitner

model (relevant part):

class AcmeSapPricelist(models.Model):
    _name = "acme.sap.pricelist"
    _inherit = 'portal.mixin'
    _description = "Some Model"
    _order = 'date desc, id desc'
    partner_id = fields.Many2one('res.partner', string='Partner', required=True)
    company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.user.company_id)
    name = fields.Char(string='Document name')
    origin = fields.Char(string='Document origin/source')
    date = fields.Datetime(string='Document creation date')
    note = fields.Char(string='Note')
    file = fields.Many2one(comodel_name="ir.attachment", string="SAP file")
    pricelist_lines = fields.One2many('acme.sap.pricelist.line', compute='_pricelist_lines', store=False)
    @api.multi
    def _pricelist_lines(self):
        self.pricelist_lines = request.env['acme.sap.pricelist.line'].search([('sap_pricelist_id', '=', 1)])


view (relevant part):

        <record id="view_acme_sap_pricelist_form" model="ir.ui.view">
            <field name="name">acme.sap.pricelist.form</field>
            <field name="model">acme.sap.pricelist</field>
            <field name="priority" eval="8" />
            <field name="arch" type="xml"> 
                <form string="Pricelist">
                    <sheet>
                        <div class="oe_title">
                            <h1>
                                <field name="name"/>
                            </h1>
                        </div>
                        <group>
                            <group>
                                <field name="date"/>
                                <field name="id"/>
                            </group>
                            <group>
                                <field name="partner_id"/>
                                <field name="csv"/>
                            </group>
                        </group>
                        <group>
                            <group>
                                <field name="origin"/>
                                <field name="note"/>
                            </group>
                        </group>
                    </sheet>
                </form>
            </field>
        </record>


 

Above (file = fields.Many2one(comodel_name="ir.attachment", string="SAP file")) is writing a record to ir.attachment table, however I'm unable to figure how to get the columns

res_model
res_model_name
res_field
res_id

filled too. All of them are set to NULL when uploading an file making it impossible to process the record further.


Based on some testing, at least res_model (=>res.partner in this case) and res_id (=>the partners Id) would be required (i.e. for allowing a website user to access the attachment via /web/content/id). How can I tell my module to pass on these two? 

0
Avatar
Opusti
Avatar
Christoph Farnleitner
Avtor Best Answer

My approach now looks the following - seems like that's how you're supposed to do it:

model:

    @api.onchange('partner_id')
    def onchange_partner_id(self):
        if(self.csv):
            if(self.partner_id):
                self.csv.write({'res_model': 'res.partner', 'res_field': 'woa_sappricelist', 'res_id': self.partner_id})


view:

    <field attrs="{'invisible':[('partner_id', '==', False)]}" name="csv" context="{'default_res_model': 'res.partner', 'default_res_id': partner_id}"  />


attrs .. invisible is just do hide the field as long as no partner is selected, which just helps to make sure there is a partner selected before uploading a file.


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

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

Prijavi
Related Posts Odgovori Prikazi Aktivnost
Creating Attachments For account.invoice in odoo 12? Solved
attachments ir.attachment odoo12
Avatar
1
jan. 23
10289
[odoo12]How to update data inside a custom module Solved
update sql custommodule odoo12
Avatar
Avatar
2
jul. 20
4591
psycopg2.ProgrammingError When deleting record Solved
delete psycopg2 custommodule odoo12
Avatar
Avatar
5
dec. 19
6213
Odoo Mail Sending Limit Solved
odoo12
Avatar
Avatar
Avatar
2
dec. 23
16446
(Document type: Invoice, Operation: write) - (Records: [], User: 2)
odoo12
Avatar
0
okt. 23
33
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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