Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

Adding Cost Column and Gross profit to Point of Sale detail report

By
Daniel
on 3/9/16, 7:00 PM 566 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.

1

Axel Mendoza

--Axel Mendoza--
10203
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 3/11/16, 3:40 AM

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, 

0
Daniel
On 3/12/16, 2:08 AM

Hello, 

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 3/9/16, 7:00 PM
Seen: 566 times
Last updated: 5/23/16, 10:58 AM