This question has been flagged
4 Replies
6234 Views

Pls, anyone in house that could guide me on how to extend Odoo 8 point of sale report? I want to add two columns to Details of Sales. The column will be Cost price and Gross profit per line.

Then later have a summary of Total sales and Gross profit.

I thank you all in advance.

Avatar
Discard
Best Answer

To do that you need to inherit the class pos_details using python inheritance and registered as a parser by inheriting the abstract model report.point_of_sale.report_detailsofsales using odoo inheritance by extention to be able to set the new parser class extension. In the new parser class you need to override the method _pos_sales_details that it's the responsible for build the data used for the sale report detail table that you need to add the new columns, in that method you need to extend the result dict with the new data to the report. like:

from openerp.osv import osv

from openerp.addons.point_of_sale.report.pos_details import pos_details

class pos_details_parser(pos_details):

def __init__(self, cr, uid, name, context):

super(pos_details_parser, self).__init__(cr, uid, name, context=context)

self.gross_total = 0.0

self.localcontext.update({

'pos_sales_details':self._pos_sales_details,

'getgrosstotal': self._get_gross_total,

})

def _pos_sales_details(self, form):

pos_obj = self.pool.get('pos.order')

user_obj = self.pool.get('res.users')

data = []

result = {}

user_ids = form['user_ids'] or self._get_all_users()

company_id = user_obj.browse(self.cr, self.uid, self.uid).company_id.id

pos_ids = pos_obj.search(self.cr, self.uid, [('date_order','>=',form['date_start'] + ' 00:00:00'),('date_order','<=',form['date_end'] + ' 23:59:59'),('user_id','in',user_ids),('state','in',['done','paid','invoiced']),('company_id','=',company_id)])

for pos in pos_obj.browse(self.cr, self.uid, pos_ids):

for pol in pos.lines:

result = {

'code': pol.product_id.default_code,

'name': pol.product_id.name,

'invoice_id': pos.invoice_id.id,

'price_unit': pol.price_unit,

'qty': pol.qty,

'discount': pol.discount,

'total': (pol.price_unit * pol.qty * (1 - (pol.discount) / 100.0)),

'date_order': pos.date_order,

'pos_name': pos.name,

'uom': pol.product_id.uom_id.name,

'cost_price': pol.product_id.standard_price,

'gross_profit': pol.product_id.list_price - pol.product_id.standard_price,

# or

#'gross_profit': ((pol.product_id.list_price - pol.product_id.standard_price) * pol.qty * (1 - (pol.discount) / 100.0)),

}

data.append(result)

self.total += result['total']

self.qty += result['qty']

self.discount += result['discount']

self.total += result['total']

self.gross_total += result['gross_profit']

if data:

return data

else:

return {}

def _get_gross_total(self):

return self.gross_total

class report_pos_details(osv.AbstractModel):

_inherit = 'report.point_of_sale.report_detailsofsales'

_wrapped_report_class = pos_details_parser

With that code in place you need to use it in the report template like:

<template id="report_detailsofsales" inherit_id="point_of_sale.report_detailsofsales">

<xpath expr="//table[@class='table table-condensed'][1]/thead" position="inside">

<th class="text-center"><strong>Cost Price</strong></th>

<th class="text-center"><strong>Gross Profit</strong></th>

</xpath>

<xpath expr="//table[@class='table table-condensed'][1]/tbody/tr" position="inside">

<td class="text-center">

<span t-esc="formatLang(line_ids['cost_price'], dp='Sale Price')"/>

</td>

<td class="text-center">

<span t-esc="formatLang(line_ids['gross_profit'], dp='Sale Price')"/>

</td>

</xpath>

<xpath expr="//table[@class='table table-condensed'][2]" position="inside">

<tr>

<td><strong>Total Gross Profit</strong></td>

<td class="text-right">

<strong t-esc="formatLang(getgrosstotal(), dp='Sale Price', currency_obj = res_company.currency_id)"/>

</td>

</tr>

</xpath>

</template>

And now test it all of this, review the gross_profit calculation because I put 2 versions of how to do it depending of what you need to display. I don't test it, this is just an example of the steps that I would do it but probably it will run ok without modifications.
Hope this helps, 

Avatar
Discard
Best Answer

Hi Daniel,

Check this module below it may help you

https://www.odoo.com/apps/modules/10.0/pos_custom_report/

Avatar
Discard
Best Answer

what is the meaning of "pol" in pol.product_id.standard_price ??

i'd like to change the "standard_price" in product.template into "price" in product.supplierinfo.

how to change it? thanks

Avatar
Discard
Author Best Answer

Hello, 

Where can we apply the below code please. Any idea is highly welcome.

Avatar
Discard