I have tried to add page numbers in my document using the following two ways
I just want default page 1, page 2 etc.
1)
<para>
<drawCentredString x="18.5cm" y="1.5cm"> Page: <pageNumber/></drawCentredString></para>
2)
<para><drawCentredString x="18.5cm" y="1.5cm"> Page: <pageCount/></drawCentredString></para>
for option 2, I changed the pagecount class in trml2pdf.py as below
class PageCount(platypus.Flowable):
def draw(self):
self.canv.beginForm("pageCount")
self.canv.setFont("Helvetica", utils.unit_get(str(8)))
## self.canv.drawString(0, 0, str(self.canv.getPageNumber()))
self.canv.drawString(0, 0, str(self.canv._pageCount))
self.canv.endForm()
class PageReset(platypus.Flowable):
def draw(self):
self.canv._pageNumber = 0
--
No Luck !! I just get page : or or
error
Thanks in advance,Usha
You can do so by just writing "< pageNumber/>" in your .rml, but you have to write it under "template/paggeTemplate/pageGraphics" tags.
For example:
<template pageSize="(595.0,842.0)" title="Test" author="Martin Simon" allowSplitting="20">
<pageTemplate>
<pageGraphics>
<drawCentredString x="10.5cm" y="0.8cm">Page: <pageNumber/></drawCentredString>
</pageGraphics>
</pageTemplate>
Hope this will solve your problem.
For the report with header = internal , you will have the 1/2 style page Count in report automatically .
as in report of openerp it is using Numbered canvasing for the internal Heard report .
Related
I was inherited some fields in product.category model and i want to show that some other fields on my other companies.. I am tried to give the answer on create function and Also tried on other Button But i can't write the values that i give in the main company to other companies.. Please Help me to find the Answer..
#api.model
def create(self, vals_list):
res = super(ProductCentralized, self).create(vals_list)
vals = []
vals.append({
'property_cost_method': res.property_cost_method,
'name':res.name,
'property_valuation': res.property_valuation,
'property_stock_valuation_account_id': res.property_stock_valuation_account_id,
'property_stock_journal': res.property_stock_journal,
'property_stock_account_input_categ_id': res.property_stock_account_input_categ_id,
'property_stock_account_output_categ_id': res.property_stock_account_output_categ_id,
})
res.sudo().create({'property_cost_method': self.property_cost_method,
'name': self.name,
'property_valuation': self.property_valuation,
'property_stock_valuation_account_id': self.property_stock_valuation_account_id,
'property_stock_journal': self.property_stock_journal,
'property_stock_account_input_categ_id': self.property_stock_account_input_categ_id,
'property_stock_account_output_categ_id': self.property_stock_account_output_categ_id})
return res
Please Help me to correct this code or using another button.. Thanks in Advance..
Consider changing the corresponding view : "res.partner.form" instead. You can find it this way : in App Settings, switch to debug mode by adding "?debug=1" in your url, reload the page, then go to the new Technical Menu-tab > View.
Then you can display your partner/company(id= 1344 ) fields, using :
For Back-Office :
<t t-esc="self.env['res.partner'].browse(1344).name" />
For Front-Office :
<t t-esc="request.env['res.partner'].browse(1344).name" />
Or you can display your product_template (id= 135 ) fields, using :
<t t-esc="self.env['product.template'].browse(135).property_valuation" />
Or you can display your stock fields, using :
<t t-esc="self.env['stock.quant'].search([('product_id','=','5')]).location_id.name" />
I want to compute a telephone number, if the number in the 8 position is either "0" or "1" I want to print just the last 4 numbers with a "(3)" before them, otherwise just print the 4 numbers, but what is happening is that my code is printing "0.0" and I don't know why, I'll appreciate your help...
This is my python code:
class Employee(models.Model):
_inherit = "hr.employee"
marcado_rapido = fields.Float("MarcadoRapido",compute='_compute_marcado_rapido')
#api.onchange("emp.marcado_rapido")
def onchange_compute_marcado_rapido(self):
for num in self:
num = "809-257-1457"
if num[8] in ('0','1'):
"(3)"+num[8:]
This is my xml code:
<td>
<t t-foreach="env['hr.employee'].search([('department_id', '=', dep.id)])" t-as="emp">
<div class="contact_form">
<img t-if="emp.image" t-att-src="'data:image/png;base64,%s' % to_text(emp.image)"/>
<div class="bloqueP">
<div class="bloque" t-field="emp.marcado_rapido"/>
</div>
</div>
</t>
</td>
#onchange only supports simple field names, dotted names (fields of relational fields e.g. partner_id.tz) are not supported and will be ignored
You can check the official documentation on how the onchange decorator works and what are the limitations.
0.0 is the default value for float fields and the value of marcado_rapido is computed using _compute_marcado_rapido function. If the field updated in onchange method depends on marcado_rapido field value, you can compute its value using the same method
You should use compute decoration instead of onchange, but compute method aproach always depend in someone else field. My sugestion is use a another computed field, something like this:
class Employee(models.Model):
_inherit = 'hr.employee'
# If your number contains special characters(like '-') you should use `Char` insted of `float`
num_telefono = fields.Char('Num. Telefono')
marcado_rapido = fields.Char('MarcadoRapido', compute='_compute_marcado_rapido')
#api.depends('num_telefono')
def _compute_marcado_rapido(self):
for rec in self:
num = rec.num_telefono[-4:]
rec.marcado_rapido = '(3){}'.format(num) if num[:1] in ('0','1') else num
Now you can call marcado_rapido from your XML.
I hope this answer can be helful for you.
I'm new in this community and I setting up Odoo Community version for my little comapny. I does all the things just doesn't know how to set up num2words to show Total Amount in Invoice Reports!
I found num2words api in res_currency.py in Base/Modules but I spend two days researching how to connect and nothing. What I have to inherite and how and also what to put in invoice document qweb?
I made module like this:
from num2words import num2words
class account_invoice(models.Model):
_inherit = "account.invoice"
#api.multi
def amount_to_text(self, amount):
self.ensure_one()
def _num2words(number, lang):
try:
return num2words(number, lang=lang).title()
except NotImplementedError:
return num2words(number, lang='en').title()
if num2words is None:
logging.getLogger(__name__).warning("The library 'num2words' is missing, cannot render textual amounts.")
return ""
formatted = "%.{0}f".format(self.decimal_places) % amount
parts = formatted.partition('.')
integer_value = int(parts[0])
fractional_value = int(parts[2] or 0)
lang_code = self.env.context.get('lang') or self.env.user.lang
lang = self.env['res.lang'].search([('code', '=', lang_code)])
amount_words = tools.ustr('{amt_value} {amt_word}').format(
amt_value=_num2words(integer_value, lang=lang.iso_code),
amt_word=self.currency_unit_label,
)
if not self.is_zero(amount - integer_value):
amount_words += ' ' + _('and') + tools.ustr(' {amt_value} {amt_word}').format(
amt_value=_num2words(fractional_value, lang=lang.iso_code),
amt_word=self.currency_subunit_label,
)
return amount_words
Got error like this:
Error to render compiling AST
AttributeError: 'NoneType' object has no attribute 'currency_id'
Template: account.report_invoice_document_with_payments
Path: /templates/t/t/div/p[1]/span
Node: <span t-if="doc.currency_id" t-esc="doc.currency_id.amount_to_text(doc.amount_total)"/>
In QWeb I put this:
<span t-if="doc.currency_id" t-esc="doc.currency_id.amount_to_text(doc.amount_total)"/>
Thank you in advance!
In your case "currency_id" is a Many2one field. The 'res.currency' model does not contain the class 'amount_to_text' function.
You have written amount_to_text function in 'account.invoice' model. So change your like this,
<span t-if="doc.currency_id" t-esc="doc.amount_to_text(doc.amount_total)"/>
OR(if you don't have currency_id field in your object)
<span t-if="doc.amount_to_text" t-esc="doc.amount_to_text(doc.amount_total)"/>
Please use the below code
<span t-if="o.currency_id" t-esc="o.amount_to_text(o.amount_total)"/>
You are getting the error because in the base report they are using o instead of doc. please see the below part of code from base.
<t t-foreach="docs" t-as="o">
So try to use o instead of doc
I am having problems calling specific attributes in beautifulsoup
<div class="route_list "
data-id="11234"
data-lazy="ubt"
data-ubt-company="ABC"
data-ubt-departuredate="2016-11-10"
data-ubt-destcountry="China,"
data-ubt-from="Shanghai"
data-ubt-mark="Bus"
data-ubt-price="2399"
data-ubt-sailingid="11185"
data-ubt-score="4.4"
data-ubt-sourcefrom="Cruise"
data-ubt-voyaid="1184">
I am trying to extract only the company and departure date and the following code returns a key error.
bsObj = BeautifulSoup(html.read(), "html.parser")
div=bsObj.div
departure = div.attrs['data-ubt-departuredate']
You might not be targeting the desired div, narrow down your search:
div = bsObj.find("div", class_="route_list")
Or, checking the presence of the data-ubt-departuredate attribute:
div = bsObj.find("div", {"data-ubt-departuredate": True})
I use this method
allcity = dom.body.findAll(attrs={'id' : re.compile("\d{1,2}")})
to return a list like this:
[<a onmousedown="return c({'fm':'as','F':'77B717EA','F1':'9D73F1E4','F2':'4CA6DE6B','F3':'54E5243F','T':'1279189248','title':this.innerHTML,'url':this.href,'p1':1,'y':'B2D76EFF'})" href="http://www.ylyd.com/showurl.asp?id=6182" target="_blank"><font size="3">掳虏驴碌路驴碌脴虏煤脨脜脧垄脥酶 隆煤 脢脦脝路脦露脕卢陆脫</font></a>,
掳脵露脠驴矛脮脮]
How do I extract this href?
http://www.ylyd.com/showurl.asp?id=6182
Thanks. :)
you can use
for a in dom.body.findAll(attrs={'id' : re.compile("\d{1,2}")}, href=True):
a['href']
In this example, there's no real need to use regex, it can be simply as calling <a> tag and then ['href'] attribute like so:
get_me_url = soup.a['href'] # http://www.ylyd.com/showurl.asp?id=6182
# cached URL
get_me_cached_url = soup.find('a', class_='m')['href']
You can always use prettify() method to better see the HTML code.
from bs4 import BeautifulSoup
string = '''
[
<a href="http://www.ylyd.com/showurl.asp?id=6182" onmousedown="return c({'fm':'as','F':'77B717EA','F1':'9D73F1E4','F2':'4CA6DE6B','F3':'54E5243F','T':'1279189248','title':this.innerHTML,'url':this.href,'p1':1,'y':'B2D76EFF'})" target="_blank">
<font size="3">
掳虏驴碌路驴碌脴虏煤脨脜脧垄脥酶 隆煤 脢脦脝路脦露脕卢陆脫
</font>
</a>
,
<a class="m" href="http://cache.baidu.com/c?m=9f65cb4a8c8507ed4fece763105392230e54f728629c86027fa3c215cc791a1b1a23a4fb7935107380843e7000db120afdf14076340920a3de95c81cd2ace52f38fb5023716c914b19c46ea8dc4755d650e34d99aa0ee6cae74596b9a1d6c85523dd58716df7f49c5b7003c065e76445&p=8b2a9403c0934eaf5abfc8385864&user=baidu" target="_blank">
掳脵露脠驴矛脮脮
</a>
]
'''
soup = BeautifulSoup(string, 'html.parser')
href = soup.a['href']
cache_href = soup.find('a', class_='m')['href']
print(f'{href}\n{cache_href}')
# output:
'''
http://www.ylyd.com/showurl.asp?id=6182
http://cache.baidu.com/c?m=9f65cb4a8c8507ed4fece763105392230e54f728629c86027fa3c215cc791a1b1a23a4fb7935107380843e7000db120afdf14076340920a3de95c81cd2ace52f38fb5023716c914b19c46ea8dc4755d650e34d99aa0ee6cae74596b9a1d6c85523dd58716df7f49c5b7003c065e76445&p=8b2a9403c0934eaf5abfc8385864&user=baidu
'''
Alternatively, you can do the same thing using Baidu Organic Results API from SerpApi. It's a paid API with a free trial of 5,000 searches.
Essentially, the main difference in this example is that you don't have to figure out how to grab certain elements since it's already done for the end-user with a JSON output.
Code to grab href/cached href from first page results:
from serpapi import BaiduSearch
params = {
"api_key": "YOUR_API_KEY",
"engine": "baidu",
"q": "ylyd"
}
search = BaiduSearch(params)
results = search.get_dict()
for result in results['organic_results']:
# try/expect used since sometimes there's no link/cached link
try:
link = result['link']
except:
link = None
try:
cached_link = result['cached_page_link']
except:
cached_link = None
print(f'{link}\n{cached_link}\n')
# Part of the output:
'''
http://www.baidu.com/link?url=7VlSB5iaA1_llQKA3-0eiE8O9sXe4IoZzn0RogiBMCnJHcgoDDYxz2KimQcSDoxK
http://cache.baiducontent.com/c?m=LU3QMzVa1VhvBXthaoh17aUpq4KUpU8MCL3t1k8LqlKPUU9qqZgQInMNxAPNWQDY6pkr-tWwNiQ2O8xfItH5gtqxpmjXRj0m2vEHkxLmsCu&p=882a9646d5891ffc57efc63e57519d&newp=926a8416d9c10ef208e2977d0e4dcd231610db2151d6d5106b82c825d7331b001c3bbfb423291505d3c77e6305a54d5ceaf13673330923a3dda5c91d9fb4c57479c77a&s=c81e728d9d4c2f63&user=baidu&fm=sc&query=ylyd&qid=e42a54720006d857&p1=1
'''
Disclaimer, I work for SerpApi.