Odoo - Python Programming Language - odoo-10

Employee Birthday List in QWeb Report :
Actually generate Qweb report employees birthday list.
But print button is one model and fetch the report is one model.
How to access the employee details in qweb report ?

in you model from where the print button is
#api.multi
def qweb_callmethod()
return SomeValue
in Qweb report
<span t-esc ="o.qweb_callmethod()" />

Related

how to display tax percentage instead of tax name in invoice odoo 8

I'm trying to display tax percentage instead of their name in accounting > customer invoices
I want to have the percentage from accounting > configuration > taxes > taxes
I don't know how to achieve this
The name_get returns a textual representation for the records in self.
By default, this is the value of the display_name field.
The method was redefined in account.tax to use the description (Code) field or the name field. In the following example, we will override the same method to show the tax amount percentage.
class AccountTax(models.Model):
_inherit = 'account.tax'
#api.multi
def name_get(self):
res = []
for record in self:
percentage = int(record.amount * 100)
name = str(percentage) + "%"
res.append((record.id, name))
return res
Edit:
To use the same representation in invoice report (which uses the name field for tax name), just call the name_get function to get the display name.
Example: Inherit invoice report to use the display name instead of tax name
<template id="report_invoice_document" inherit_id="account.report_invoice_document">
<xpath expr="//tbody[hasclass('invoice_tbody')]/tr/td[5]/span" position="attributes">
<attribute name="t-esc">', '.join(map(lambda x: x.name_get()[0][1], l.invoice_line_tax_id))</attribute>
</xpath>
</template>

Odoo - Currency sign not displaying in the qWeb

I have got a custom report and the currency sign is not displayed.
What could be wrong in this:
<span t-esc="grand_total" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/>
You should use currency from invoice object. Change t-esc to t-field. What can you see when you just add t-field="grand_total" ?
<span t-field="grand_total" t-options="{'widget': 'monetary', 'display_currency': o.currency_id}"/>

How i can show many2one field all records on a form view instead drop down list in odoo 10?

How I can show many2one field all records on a form view instead drop down list in odoo 10.
For example, I have a Product category and Products.
When I select Product category from drop down list then all products belongs to that category shows on form view instead of a drop down list.
Here I assume you have category id like,
category_id = fields.Many2one('product.category', "Product Category")
Add Many2many of product.product field to your model for product records.
product_ids = fields.Many2many('product.product', "Products")
Now you need to define onchange on category_id field like.
#api.onchange('category_id')
def onchange_product_category(self):
if self.category_id:
self.product_ids = [(5,)] # unlink all existing records of product
product_recs = self.env['product.product'].search([('categ_id', '=', self.category_id.id)])
self.product_ids = [(4, x) for x in product_recs] # link the product records of selected category
If you do not want to display your product records in list view you can use widget many2many_tags in the form view like,
<field name="product_ids" widget="many2many_tags"/>
It will work for you.

Server Action: Loop through each record of model

I have a server action to update product costs when selected in tree view:
bom_obj = env["mrp.bom"]
for product in object.browse(context.get('active_ids')):
price = 0
bom = bom_obj._bom_find(product=product)
if bom:
price = product._calc_price(bom)
product.write({'standard_price':price})
But This unfortunately only selects records visible in tree view, not ALL the records in product.product
I tried:
bom_obj = env["mrp.bom"]
product_obj = env["product.product"]
product_ids = product_obj.search(cr, uid, [])
for product in product_ids:
price = 0
bom = bom_obj._bom_find(product=product)
if bom:
price = product._calc_price(bom)
product.write({'standard_price':price})
Could you please tell me how to loop through each record of product.product.
OR
instead, tell me how I would go about update price of record selected in m2o field.
I know how to trigger the code in server action, I just need to know how to get record from m2o field. I will use this when product_id is changed in Sale Order Line, to update the price as it is selected.
Thanks

how to display data in custom table in a form view (Odoo)

I want to make some calculations with product data and display them in a custom table.
Specifically what I want to do is:
1. take a list of products of a particular invoice
2. calculate the percentage of the product price to the total value of the invoice
3. display the custom table with the name of the product and the calculated value
for example:
I have a list of the kind:
[{'name': u'Ipad', 'percentage': 45},
{'name': u'Imac', 'percentage': 20}]
How I can display the result in a notebook page of form view? Maybe I can do this with Qweb templates?, any example?, thanks.

Resources