NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

menu
Status #openobjectX leioX
[18:58] <leio> so yeah, I guess I could theoretically test this in practice too instead of blind, but I haven't really been in odoo development mode, so haven't context switched beyond blind suggestions :P
[18:58] <leio> entering what I consider billing territory otherwise, lol
[18:59] <leio> but you start getting me wondering how it's supposed to be done :D
[18:59] <leio> I mean, if to hack it up via qweb, instead of that computed field
[19:00] <tkonto> I tried both suggestions (just finished) but none gives an output. Thought that in "invoice" there is a capital i but checked with the field values in debugging mode it is with lower i
[19:00] <tkonto> Also none gives an error
[19:01] <leio> yeah, I looked at the selection list in base module that it's 'invoice' as value with "Invoice" as the UI display name
[19:01] <tkonto> so no error (so something gets calculated) but it gives null
[19:01] <leio> it actually write null in the PDF or?
[19:01] <tkonto> how about adding something in there to see what it calculates to?
[19:01] <tkonto> no sorry by null I mean it writes nothing on the pdf
[19:01] <leio> try the version with "next"
[19:02] <leio> and instead of '' put some readable default value
[19:02] <leio> <t t-esc="next((partner.name for partner in o.partner_id.commercial_partner_id.child_ids if partner.type == 'invoice'), 'List is empty')"/>
[19:02] <tkonto> Now that I think about it...
[19:02] <tkonto> ok let me run that test and share what I thought
[19:03] <leio> you don't have any contacts with type==invoice? :D
[19:03] <tkonto> :D
[19:03] <tkonto> LoL
[19:03] <tkonto> ROTFL
[19:03] <tkonto> I do
[19:03] <tkonto> assuming it calculates to nothing.
[19:03] <leio> for that invoice recipient
[19:04] <tkonto> we should see an extra empty line on the pdf between the lines I have added the t-esc for this.
[19:04] <tkonto> there are no extra empty lines
[19:04] <tkonto> (I have added both versions of t-esc actually to work in parallel and see which on will work)
[19:04] <tkonto> I have added them between two existing lines that DO create output
[19:05] <tkonto> so if the new t-esc result to nothing, at least should we not see two extra empty lines on the pdf?
[19:05] <leio> not necessarily any extra lines; there's no <p> stuff in there
[19:05] <tkonto> the test did not worked out
[19:05] <tkonto> no output still
[19:05] <leio> should at least give List is empty...
[19:05] <tkonto> it did not
[19:06] <leio> you don't use CRM or whatever thing that saves the PDF in attachments and then later just gives the saved PDF instead of re-generating? :D
[19:06] <tkonto> I remove the attachment before re-printing to avoid that.
[19:07] <tkonto> (it works for something like 123 re-prints already ) :)
[19:08] <tkonto> should the res.parnter somehow be included?
[19:08] <tkonto> s//res.partner
[19:09] <tkonto> the object and the relation is with res.partner
[19:09] <leio> slightly preoccupied with work work right now
[19:09] <tkonto> sorry
[19:09] <tkonto> :)
[19:10] <leio> so my answer will be delayed now; just something just came up
[19:10] <leio> so you know :)
[19:10] <leio> some field missing report nonsense after a server migration
[19:10] <tkonto> I feel you :)
[19:29] <leio> who what [email protected]
[19:33] <tkonto> did not catch that. a question?
[19:33] <leio> I didn't understand your res.partner question
[19:34] <tkonto> o sorry.. I was trying to figure out how we know when to address res.partner and when o.partner_id
[19:35] <leio> res.partner is a model
[19:35] <leio> o.partner_id is a reference to an entry/object of that model
[19:35] <leio> because o is an account.invoice in that context
[19:35] <leio> not the model class, but an instance of it
[19:35] <leio> or well
[19:35] <tkonto> got it
[19:35] <leio> and account.invoice model has a field called partner_id
[19:36] <leio> which is a many2one of res.partner
[19:36] <leio> so o.partner_id IS a concrete res.partner
[19:36] <leio> (unless it's not set, which shouldn't be possible, as partner_id on account.invoice is required=True)
[19:37] <leio> o.partner_id.id is the database row ID of that res.partner entry
[19:37] <leio> the database table is by default with dot stuff smashed to _, so it's res_partner table ID column
[19:37] <leio> for .id
[19:37] <tkonto> so we are trying to get the name of a partner if that partner type == invoice and that partner being a child_id under a commercial_partner_id under a partner_id
[19:37] <leio> in turn res.partner has a computed commercial_partner_id field
[19:38] <leio> which is also a res.partner
[19:38] <leio> openerp/addons/base/res/res_partner.py has code for that
[19:38] <leio> 'commercial_partner_id': fields.function(_commercial_partner_id, type='many2one', relation='res.partner', string='Commercial Entity', store=_commercial_partner_store_triggers)
[19:39] <leio> this is old v7 API (it's not ported to new API yet in odoo v8, should be in v9) relation='res.partner' says
[19:39] <leio> that it's also a res.partner many2one (type= said that)
[19:39] <leio> it ends up via some indirection in def _commercial_partner_compute function in there
[19:40] <leio> the store_triggers are old API way of doing @api.depends
[19:40] <leio> needed because it actually caches the computed value in database
[19:40] <leio> and it tells when it has to recompute
[19:41] <leio> but what the value is, is just the code in that compute function
[19:41] <leio> """ Returns the partner that is considered the commercial
[19:41] <leio> entity of this partner. The commercial entity holds the master data
[19:41] <leio> for all commercial fields (see :py:meth:`~_commercial_fields`) """
[19:42] <leio> in practice, a commercial entity is a res.partner that has is_company set, or a non-company that isn't just a contact of some company
[19:43] <tkonto> could be just a person, with no affiliation to any company.. yes
[19:43] <leio> based on that it does accounting stuff against the commercial entity, instead of a contact inside a company
[19:43] <leio> so if you invoice a contact partner, it should invoice the company instead, etc
[19:43] <leio> I'm not familiar with how the partner_id gets set on account.invoice
[19:43] <tkonto> it does but reporting still references the contact not the company
[19:44] <leio> MAYBE it already is assured to be a commercial entity and we don't have to go via commercial_partner_id there
[19:44] <leio> guess not then
[19:44] <leio> that's why I put that inbetween
[19:44] <leio> because you probably want to find an invoice type contact of the company, not the contact
[19:44] <tkonto> I THINK I tried without comercial_partner_id... let me check once more
[19:45] <leio> it's business logic, I don't know what you need
[19:45] <leio> I assume you want to search all contacts of the company for an invoice type contact
[19:45] <tkonto> exactly that
[19:45] <leio> so you need commercial_partner_id in there
[19:45] <tkonto> and just present the name of it on the report
[19:45] <leio> nothing assures only one such contact exists
[19:45] <leio> so my code just more or less randomly picks one
[19:45] <leio> would need slightly different code to list them all
[19:46] <leio> however itd be simple
[19:46] <leio> instead of the next() trick, we'd instead create a string from the list
[19:46] <leio> via string join metho
[19:46] <leio> method
[19:46] <leio> put commas inbetween and voilǎ
[19:46] <tkonto> now you lost me completely... method like python method?
[19:47] <leio> or you might want to list the same contact you are invoicing in there IF he is already a type==invoice
[19:47] <leio> yeah
[19:47] <leio> and only go looking for other contacts if he himself isn't invoice type
[19:47] <leio> that depends how the logic has to be
[19:47] <tkonto> if it will work for one, I might be able to amend to that scenario
[19:48] <leio> if you want to list all of the invoice types simply separated by commas
[19:48] <leio> you could do this supposedly:
[19:48] <leio> <t t-esc="', '.join([partner.name for partner in o.partner_id.commercial_partner_id.child_ids if partner.type == 'invoice'])" />
[19:49] <leio> for example if the company has two partners marked with type=='invoice' named Foo and Bar
[19:49] <leio> this should output "Foo, Bar"
[19:49] <leio> if there are none, it will output empty string
[19:50] <leio> if there is only one, it'll just output one
[19:50] <leio> except there's some problem going on in here that shouldn't be fixed by this, maybe by coincidence :P
[19:50] <leio> as the previous versions didn't work either
[19:51] <leio> btw, there's a nice module called "shell"
[19:51] <leio> which allows you to type command line python against a database
[19:51] <leio> nice for debugging
[19:51] <leio> I'd use that to figure out what the heck is going on
[19:51] <leio> it's builtin in v9
[19:51] <leio> for v8 there's a backported module by OCA
[19:51] <leio> in its server modules
[19:51] <tkonto> I wonder if the lines I have all four versions of t-esc right now, do not show up on the pdf for a layout related reason... at least one of them should work
[19:52] <leio> https://github.com/OCA/server-tools
[19:52] <leio> the shell module in there is what I talked about
[19:52] <leio> oh, 8.0 branch
[19:52] <leio> 9.0 doesn't have it - odoo has it on its own there
[19:52] <leio> https://github.com/OCA/server-tools/tree/8.0/shell
[19:52] <leio> then we could double-check via that if the data is right
[19:52] <leio> if it works outside qweb
[19:53] <leio> you would find out what invoice ID you are printing
[19:53] <leio> it should be in the URL of the invoice form
[19:53] <leio> like id=1 and model=account.invoice in the URL bar of browser
[19:54] <leio> you could take the ID
[19:54] <leio> open this shell
[19:54] <leio> and debug there
[19:54] <leio> o = env['account.invoice'].browse(1)
[19:54] <leio> (where instead of 1 you'd put what ID it is
[19:54] <leio> and then you can test if it works in python
[19:54] <leio> ', '.join([partner.name for partner in o.partner_id.commercial_partner_id.child_ids if partner.type == 'invoice'])
[19:54] <leio> by just launching that
[19:54] <leio> see if it outputs something or also empty string
[19:55] <leio> this assumes you figure out how to launch odoo from the command line
[19:55] <leio> you probably would make your odoo user possible to log in
[19:55] <leio> su into it
[19:55] <tkonto> I am ok with that... my main job is related to system/services admin
[19:55] <leio> and then run odoo.py with the same arguments the service is doing
[19:55] <leio> probably some --config arg mainly
[19:56] <leio> but putting shell in front
[19:56] <leio> so like odoo.py shell --config...
[19:56] <leio> but also need to specify what database you want to shell into
[19:56] <tkonto> yeap
[19:56] <leio> so a -d <db_name> extra arg
[19:56] <leio> before all that you would install the shell module into that db
[19:56] <leio> then it works
[19:56] <tkonto> the config file is basic actually so no strange options... it should be strait forward
[19:56] <leio> this is a debug tool, so presumbly would do it on a development instance :)
[19:57] <leio> yeah, mostly for addons_path or so
[19:57] <leio> the one it auto-generates
[19:57] <leio> I like to comment out the log-file or whatever thing
[19:57] <tkonto> I have a container for playing and destroying.. I tested all your suggestions on that actually
[19:57] <leio> because the servce seems to be passing a logfile on command line anyways
[19:57] <leio> that way I can see the log in console when running from command line manually
[19:58] <leio> instead of having it hidden away in /var/log that I need to tail -f separately then
[19:58] <leio> but not important for the shell case
[19:58] <leio> for poking at it at shell, the main service itself can continue running even
[19:58] <leio> as if you do the shell thing, it won't go trying to open ports and stuff
[19:59] <tkonto> good to know.is there something we could add into that t-esc to force it output something?
[19:59] <leio> not sure, it should be outputting it pretty raw
[19:59] <leio> with shell we could debug easier what's going on
[20:00] <tkonto> ok one moment
[20:00] <tkonto> is the following valid?
[20:00] <tkonto> <t t-esc="'TEST'"/>
[20:00] <tkonto> should it just output TEST?
[20:01] <leio> I think so...
[20:01] <leio> try :)
[20:01] <tkonto> it does not
[20:01] <tkonto> I think there is something else wrong... ok
[20:01] <leio> put it all inbetween paragraph tags to be sure?
[20:01] <leio> <p><t ...></p>
[20:01] <tkonto> let me try different div sections / report lines and come back... maybe your code is correct, and the layout does not show up the output
[20:02] <tkonto> will update you in a while..
[20:03] <leio> you can try to see if just raw text shows up or something
[20:03] <leio> like if <p><t t-esc="'TEST'"/></p> doesn't show up
[20:03] <leio> try just <p>TEST</p> in that location
[20:04] <leio> to make sure t-esc is working like we think it works :D
[20:04] <leio> I tend to make computed fields and use t-field, so I actually might just say some nonsense about esc :(
[21:01] <tkonto> As I thought
[21:02] <tkonto> The place I had the code in, did nothing to the pdf
[21:02] <tkonto> I changed it and it works
[21:02] <tkonto> and for reference, let me check all four versions of it.
[21:02] <leio> if you want to list all of them, the ", ".join(...) version is probably best
[21:02] <leio> so it would list them all
[21:03] <leio> if you want to avoid printing some label in front if there are no results
[21:03] <leio> you would probably save it in a qweb variable via t-set instead
[21:03] <leio> then you can t-if and t-esc on it not being empty
[21:04] <leio> without needleslly running the expression multiple times
[21:18] <tkonto> yeap very good idea
[21:18] <tkonto> results
[21:18] <tkonto> QWebException: ""'NoneType' object is not callable" while evaluating "next((partner.name for partner in o.partner_id.commercial_partner_id.child_ids if partner.type == 'invoice'), 'TEST')"" while evaluating
[21:20] <tkonto> QWebException: ""'NoneType' object is not callable" while evaluating
[21:20] <tkonto> "next((partner.name for partner in o.partner_id.commercial_partner_id.child_ids if partner.type == 'invoice'), '')"" while evaluating
[21:21] <tkonto> so it seams that his syntax has something missing or should be syntaxed differently
[21:22] <tkonto> s/his/this
[21:23] <tkonto> so what works is:
[21:23] <tkonto> <t t-esc="', '.join([partner.name for partner in o.partner_id.commercial_partner_id.child_ids if partner.type == 'invoice'])" />
[21:23] <tkonto> &
[21:23] <tkonto> <t t-esc="[partner.name for partner in o.partner_id.child_ids if partner.type == 'invoice'][0]"/>
[21:24] <leio> latter should break when there is no invoice type contact
[21:24] <leio> but the join is best anyway if you like the multiple case listing them all, comma-separated
[21:25] <leio> for the errors, it would be easier to figure out from using shell
[21:25] <tkonto> true it breaks
[21:25] <tkonto> QWebException: ""list index out of range" while evaluating
[21:25] <tkonto> "[partner.name for partner in o.partner_id.child_ids if partner.type == 'invoice'][0]"" while evaluating
[21:27] <tkonto> So theoretically I could even create a new value on type.. one to show as invoiced addressed to and one to show as Attention to:
[21:27] <leio> or we don't need to care what's wrong if the best output that handles all cases works :D
[21:27] <tkonto> yes you are right.. the more generic is always good
[21:29] <leio> if you need something else, you can use the [0] version without [0]
[21:29] <leio> in a t-set
[21:29] <leio> to save the list of names
[21:30] <leio> and then work with that; but it's really just a random order, not sure how you would differentiate as the main invoice person from attention to
[21:30] <tkonto> and yes the comma works... all contacts with type=invoice are comma listed
[21:30] <leio> because it's random, might want to throw in some sorting
[21:30] <tkonto> now that I have the basic t-esc, I can do many things thank's to you.
[21:30] <tkonto> Really really thank you

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.