How to rename partner ledger report in odoo8? - odoo

Partner ledger report name is 'account.report_partnerledger.pdf' by default. I want to change it to customer name (eg: john.pdf if customer name is john). How to do this?

Install report_custom_filename.
Go to Settings > Actions > Reports and search for Partner Ledger.
Fill in the Download filename field. This field is evaluated as jinja2 template with objects being a list of browse records of the records to print, and o the first record. If your model contains a name field, you might write something like ${o.name}_report.pdf as filename.

Possible through complex coding but thanks to odoo community we have one module named
report_custom_filename
which will let you do this by little configuration

Install 'report_custom_filename' module and make the following changes in report_routes method
def report_routes(self, reportname, docids=None, converter=None, **data):
cr, uid, context,registry = request.cr, request.uid, request.context,request.registry
response = super(ReportController, self).report_routes(
reportname, docids=docids, converter=converter, **data)
if docids:
docids = [int(i) for i in docids.split(',')]
report_xml = http.request.session.model('ir.actions.report.xml')
report_ids = report_xml.search(
[('report_name', '=', reportname)])
options_data = simplejson.loads(data['options'])
partner_id = options_data.get('ids')
for report in report_xml.browse(report_ids):
if not report.download_filename:
continue
#objects = http.request.session.model(report.model).browse(docids or [])
objects = request.registry[report.model].browse(cr, uid, partner_id, context=context)
customer_name = str(objects.name)
generated_filename = email_template.mako_template_env\
.from_string(report.download_filename)\
.render({
'objects': objects,
'o': customer_name,
'object': objects[:1],
'ext': report.report_type.replace('qweb-', ''),
})
response.headers['Content-Disposition'] = content_disposition(
generated_filename)
return response

Related

How to get a product's multiple locations in odoo?

I want to get a product's location and display it on a custom report table:
and on the "Warehouse" cell it should be all the product's location, so if that product has multiple it should be displayed there. Just for clarification this is the location I'm talking about:
In order to put that there I tried this code:
class StockInventoryValuationReport(models.TransientModel):
_name = 'report.stock.inventory.valuation.report'
_description = 'Stock Inventory Valuation Report'
location_id = fields.Many2one('stock.location')
# filter domain wizard
#api.multi
def _compute_results(self):
self.ensure_one()
stockquant_obj = self.env['stock.quant'].search([("location_id", "=", self.location_id.id)])
print(stockquant_obj.location_id)
line = {
'name': product.name,
'reference': product.default_code,
'barcode': product.barcode,
'qty_at_date': product.qty_at_date,
'uom_id': product.uom_id,
'currency_id': product.currency_id,
'cost_currency_id': product.cost_currency_id,
'standard_price': standard_price,
'stock_value': product.qty_at_date * standard_price,
'cost_method': product.cost_method,
'taxes_id': product.taxes_id,
'location_id': stockquant_obj.location_id,
}
if product.qty_at_date != 0:
self.results += ReportLine.new(line)
but when I'm printing stockquant_obj.location_id it is an empty recordset basically its not finding any locations. Can someone please hint me on anything?
I actually managed to get the product's locations using this code:
class StockInventoryValuationReport(models.TransientModel):
_name = 'report.stock.inventory.valuation.report'
_description = 'Stock Inventory Valuation Report'
location_id = fields.Many2one('stock.location')
# filter domain wizard
#api.multi
def _compute_results(self):
self.ensure_one()
stockquant_obj = self.env['stock.quant'].search([("location_id", "=", self.location_id.id)])
for xyz in stockquant_obj:
line = {
'name': product.name,
'reference': product.default_code,
'barcode': product.barcode,
'qty_at_date': product.qty_at_date,
'uom_id': product.uom_id,
'currency_id': product.currency_id,
'cost_currency_id': product.cost_currency_id,
'standard_price': standard_price,
'stock_value': product.qty_at_date * standard_price,
'cost_method': product.cost_method,
'taxes_id': product.taxes_id,
'location_id': xyz.location_id,
}
if product.qty_at_date != 0:
self.results += ReportLine.new(line)
I debugged further discovering that now stock.quant() could get some record-set but odoo was expecting a singleton when on my old code was stockquant_obj.location_id so since I have seen from other people that the solution to singleton is a for loop and for that reason I added it.
The problem with this is that now not only the warehouse would be added but the same product would repeat as times as long the recordset is. How can I dodge this? How to tell python that I only need to loop through stockquant_obj and xyz should be inside the line variable?

Fill up items from parent sale order to wizard

My goal is to get all items from parent quotation, to the wizard window.
I don't know i do this right way or not, but for now i can get all the products from quotation, and don't understand how to fill them into my wizard items line.
Quotation example
Wizard on that quotation
I remove the pieces of code which not matter.
from odoo import fields, models, api
import logging
class back_to_back_order(models.Model):
_name = "back.to.back.order"
_description = "Back to Back Order"
line_ids = fields.One2many('back.to.back.order.line','back_order_id', 'Order Lines', required=True)
def get_items_from_quotation(self, context):
items = []
quotation_id = context['id']
current_quotation = self.env['sale.order'].search([('id','=',quotation_id)])
if quotation_id == current_quotation.id:
for line in current_quotation.order_line:
item = {
'product_id': line.product_id,
'qty': line.product_uom_qty,
'price': line.price_unit,
'subtotal': line.price_unit*line.product_uom_qty
}
items.append(item)
class back_to_back_order_line(models.Model):
_name = "back.to.back.order.line"
_description = "Back to Back Order"
product_id = fields.Many2one('product.product', 'Product')
back_order_id = fields.Many2one('back.to.back.order', 'Back Order')
qty = fields.Float('Quantity')
price = fields.Float('Unit Price')
subtotal = fields.Float('Subtotal')
Firstly, if you are creating a wizard, then it's very likely you should be using models.TransientModel and not model.Model for your classes.
class back_to_back_order(models.TransientModel):
...
Wizard records are not meant to be persistent; they are automatically deleted from the database after a certain time. This is why they are called transient.
You mentioned you are already able to get the Sales Order Lines within your wizard, but you aren't sure how to fill your Back to Back Order Lines with the data.
One2many and Many2many use a special "commands" format to manipulate the set of records stored in/associated with the field.
I originally found these commands on another answer but they are also covered in the Documentation.
As for your specific application, you should be able to simply create your back.to.back.order.line records and they will be linked as long as you provide the back_order_id.
#api.multi
def get_items_from_quotation(self, context):
self.ensure_one()
b2b_line_obj = self.env['back.to.back.order.line']
quotation = self.env['sale.order'].browse(context['id'])
if quotation:
back_order_id = self.id
for line in quotation.order_line:
b2b_line_obj.create({
'back_order_id': back_order_id,
'product_id': line.product_id.id,
'qty': line.product_uom_qty,
'price': line.price_unit,
'subtotal': line.price_unit * line.product_uom_qty,
})

How to Put fields of an employee in accounting through a module? (ODOO 10)

Put fields of an employee in accounting through a module
Hi. I am creating a module for a client that has a specific need. He wants us to add a price per hour to employees. That is, the price charged by the employee each hour of work. Then create a small expense report that goes into accounting.
The first thing I have done is to modify the employee module using _inherit to add two fields. Nickname that allows employees to filter by nickname. And the hourly price of that employee (what this employee charges for every hour).
employee example changes
The second has been to create a new model that allows adding employees and importing said data. In addition to adding a description.
form example
The challenge now is to link this information to the accounting module so that it will appreciate as a Journal Item and then have the copy confirmed to be appreciated as a Journal Entries.
I am really new in the development of odoo and there are many things that I am still assimilating. So the questions I have are the following:
How could I do this?
Do I have a problem with what I have done so far?
It is my first post and I would appreciate the help. Thanks in advance.
This its the code:
class EmpleadoObra(models.Model):
_inherit = 'hr.employee'
apodo = fields.Char('apodo', readonly=False, store=True)
precio_por_hora = fields.Float('Salario por hora', store=True)
#api.model
def name_search(self, name='', args=None, operator='ilike', limit=100):
args = args or []
recs = self.browse()
if name:
recs = self.search(['|', ('apodo', 'ilike', name), ('name', operator, name) ] + args, limit=limit)
return recs.name_get()
class EmpleadosProductos(models.Model):
_name = "employee.as.product"
# _inherits = {'hr.employee' : 'empleado_id'}
employee_line = fields.One2many(
'employee.line',
'id',
string='Employee Lines'
)
class EmployeLine(models.Model):
_name = 'employee.line'
descripcion = fields.Text(string='DescripciĆ³n', required=False)
employee_id = fields.Many2one(
'hr.employee',
string="Empleado",
requiered=True,
change_default=True
)
apodo = fields.Char('apodo', readonly=False)
precio_por_hora = fields.Float('precio_por_hora')
_rec_name = 'apodo'
#api.onchange('employee_id')
def onchange_employee_id(self):
addr = {}
if not self.employee_id.display_name:
return addr
if not self.employee_id.apodo:
self.apodo = "no apodo"
else:
self.apodo = self.employee_id.apodo
self.precio_por_hora = self.employee_id.precio_por_hora
return addr

Openerp get partner category tags

I have 2 fields in my custom module:
'originator_id' : fields.many2one("res.partner",string="Originator", required=True),
'originator_category_ids' : fields.many2many('res.partner.category',
'module_category_rel',
'module_id',
'category_id',
'Categories'),
I want to set the domain for the many2many field "originator_category_ids" according to the selected "originator_id" which is a partner_id. I wrote an onchange method to define the domain dynamically:
def get_domain_originator_category_ids(self,cr,uid,ids,originator_id,context=None):
if originator_id:
obj = self.pool.get('res.partner').browse(cr, uid, originator_id)
return {'domain':{'originator_category_ids':[('id','in',obj.category_id)]}}
But above doesn't work.
Your support will be much appreciated.
This is worked for me, but it is a temporary solution until I find a better one. The solution consist on looping on categories and compare with the selected partner in the partner_ids field:
def get_domain_originator_category_ids(self,cr,uid,ids,originator_id,context=None):
category_obj = self.pool.get('res.partner.category')
category_ids = category_obj.search(cr, uid,[], context=context)
res=[]
for cateory in category_obj.browse(cr, uid, category_ids, context=context):
for partner_id in cateory.partner_ids:
if partner_id.id == originator_id:
res.append(cateory.id)
return {'domain':{'originator_category_ids':[('id','in',res)]}}
If you get a better solution please post it.

How to use field value of one object in another using self.pool.get in openerp?

This is my code in .py file.I want to fetch value of field list_price in product.product and use it in my custom module which inherits sale.order.
Can i store the value of list_price field in my custom field i.e qty_available?
When i print value of wg_qty_avail it shows None even list_price is having value 2000
class practice(osv.osv):
_inherit = 'sale.order'
_columns = {
'qty_available': fields.float('Quantity'),
}
def get_val(self, cr, uid, id, product, context=None):
result={}
wg_qty_avail = self.pool.get('product.product').browse(cr, uid,product,context=context).list_price
print "---------------------------", wg_qty_avail
result['qty_available'] = wg_qty_avail
practice()
xml file is ok..it calls the method get_val by a button click.
Please help.Where am i wrong..
You are not assigning the value to 'qty_available' field correctly
Remove result['qty_available'] = wg_qty_avail
return {'value': {'qty_available':wg_qty_avail}}
Hope this helps...