how to display tax percentage instead of tax name in invoice odoo 8 - 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>

Related

Qty available by location (again)

I know this was discussed before but it's not really working for me. How can i get qty available for location or warehouse my product is now.
(Most of the answers are in old API and this one not really working for me)
class ProductProduct(models.Model):
_inherit = 'product.template'
available_qty = fields.Integer(
string='Qty By Loc',
compute='product_qty_location_check',
)
def product_qty_location_check(self):
if self:
self.available_qty = self.with_context({'location' : self.source_location.id}).qty_‌​available
AttributeError: 'product.template' object has no attribute 'source_location'
To get the quantity by location you need to search the location with the product_id in stock.quant
Use the below sample in your compute function:
quant_sr = self.env["stock.quant"].search([('location_id','=',self.source_location.id),('product_id','=',self.product_id.id)])
qty = 0.0
for quant in quant_sr:
qty += quant.qty
print qty
First you have to find out your location and/or warehouse. There are enough possibilities to do so:
use a wizard which has a field
search by reference e.g. self.env.ref('my_module.my_location')
use other sources
Now you can use them on product.product's _product_available(). Just call that method on one or more products (recordssets) and evaluate the result of this method. To filter for locations and/or warehouses use the context. For example:
# get a recordset of all products
products = self.env['product.product'].search([])
# get a special location (my_location)
location = self.env.ref('my_module.my_location')
quantities = products.with_context(location=location.id)._product_available()
# print the quantities
for product_id, quantity_dict in quantities.iteritems():
print product_id
print quantity_dict
The same is possible with with_context(warehouse=warehouse.id) or even with list of IDs or names: with_context(location=[1,2,3]), with_context(location="My Location")

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.

Odoo - Python Programming Language

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()" />

How to show region specific products magento?

how to show products in Magento based on selected state and city? is
there any extension available for this feature? or how can i achieve
this?
You can add one (city) or two (state and city) attributes in product model (by back-office panel).
Your news attributes can be contain the list (in example string with delimiter commas) with the list of state/city where the product is allowed to be sell.
For retrieve your state/city allowed list you can :
<?php
// id product is 12345
// the city allowed list attribute code is 'city_list'
$id = 12345;
$product = Mage::getModel('catalog/product')->load($id);
$cityList = $product->getAttributeText('city_list');
var_dump($cityList);
Output something like this :
string(38) "Los Angeles, New Delhi, Caen, etc, etc"
It's possible that you may be add ->getAttributeToSelect('city_list') after load($id) if the attribute isn't retrieve by catalog/product model.

Display tax class in Magento

I want to display the tax name that applies to a product on the product page (the same tax class that is configured on the product).
This is what I wan to show:
Price: 100 U$S + Sample Tax
Thanks!
This returns the Name of the Tax-Class:
$taxClassId = $_product->getTaxClassId();
$taxClass = Mage::getModel('tax/class')->load($taxClassId);
$taxClassName = $taxClass->getClassName();

Resources