I make a module to add invoice pivot table.
report_stock_owner_invoice.py
import logging
import os
from openerp import models, fields, modules, api
from openerp.tools.sql import drop_view_if_exists
import openerp.addons.decimal_precision as dp
_logger = logging.getLogger(__name__)
class ReportStockOwnerInvoice(models.AbstractModel):
_name = 'report.stock.owner.invoice'
_auto = False
invoice_id = fields.Many2one('account.invoice', string='Invoice Reference', readonly=True)
invoice_state = fields.Selection([
('draft','Draft'),
('proforma', 'Pro-forma'),
('proforma2', 'Pro-forma'),
('open', 'Open'),
('paid', 'Paid'),
('cancel', 'Cancelled'),
], string='Invoice Status', readonly=True)
amount_total = fields.Monetary(string='Invoice Total', readonly=True)
sale_order_name = fields.Char(string='Order Reference', readonly=True)
client_order_ref = fields.Char(string='Customer Reference', readonly=True)
order_state = fields.Selection([
('draft', 'Quotation'),
('sent', 'Quotation Sent'),
('sale', 'Sale Order'),
('done', 'Done'),
('cancel', 'Cancelled'),
], string='Order Status', readonly=True)
product_id = fields.Many2one('product.product', string='Product', readonly=True)
categ_id = fields.Many2one('product.category', string='Internal Category', readonly=True)
quantity = fields.Float(string='Quantity', digits=dp.get_precision('Product Unit of Measure'), readonly=True)
uom_id = fields.Many2one('product.uom', string='Unit of Measure', readonly=True)
price_unit = fields.Float(string='Unit Price', readonly=True)
price_subtotal = fields.Monetary(string='Amount', readonly=True)
partner_invoice_id = fields.Many2one('res.partner', string='Invoiced Partner', readonly=True)
partner_shipping_id = fields.Many2one('res.partner', string='Delivery Partner', readonly=True)
partner_shipping_street = fields.Char('Delivery Street', readonly=True)
partner_shipping_street2 = fields.Char('Delivery Street2', readonly=True)
partner_shipping_state_id = fields.Many2one("res.country.state", 'Delivery State', readonly=True)
partner_shipping_zip = fields.Char('Delivery Zip', readonly=True)
partner_shipping_city = fields.Char('Delivery City', readonly=True)
partner_shipping_country_id = fields.Many2one('res.country', 'Delivery Country', readonly=True)
currency_id = fields.Many2one('res.currency', readonly=True)
def init(self, cr):
path_data = os.path.join(modules.get_module_path('stock_owner_account'), 'sql')
path_view = os.path.join(path_data, 'report_stock_owner_invoice.sql')
drop_view_if_exists(cr, self._table)
with open(path_view) as f:
cr.execute(f.read())
@api.v7
def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False,
lazy=True):
if 'price_unit' in fields:
fields.remove('price_unit')
if 'amount_total' in fields:
fields.remove('amount_total')
return super(ReportStockOwnerInvoice, self).read_group(cr, uid, domain, fields, groupby, offset=0, limit=None,
context=None, orderby=False, lazy=True)
report_stock_owner_invoice.sql
CREATE OR replace VIEW report_stock_owner_invoice
AS
SELECT row_number() OVER () AS id,
account_invoice.id AS invoice_id,
account_invoice.create_date,
account_invoice.state AS invoice_state,
account_invoice.amount_total,
account_invoice.currency_id,
sale_order.name AS sale_order_name,
sale_order.client_order_ref,
sale_order.state AS order_state,
account_invoice_line.product_id,
product_template.categ_id,
account_invoice_line.quantity,
account_invoice_line.uom_id,
account_invoice_line.price_unit,
account_invoice_line.price_subtotal,
account_invoice.partner_id AS partner_invoice_id,
sale_order.partner_shipping_id,
partner_shipping.street AS partner_shipping_street,
partner_shipping.street2 AS partner_shipping_street2,
partner_shipping.city AS partner_shipping_city,
partner_shipping.state_id AS partner_shipping_state_id,
partner_shipping.zip AS partner_shipping_zip,
partner_shipping.country_id AS partner_shipping_country_id
FROM account_invoice_line
join account_invoice
ON account_invoice_line.invoice_id = account_invoice.id
left join (sale_order_line
join sale_order
ON sale_order_line.order_id = sale_order.id
join res_partner partner_shipping
ON sale_order.partner_shipping_id = partner_shipping.id
join res_country
ON partner_shipping.country_id = res_country.id
join sale_order_line_invoice_rel
ON sale_order_line_invoice_rel.order_line_id =
sale_order_line.id)
ON sale_order_line_invoice_rel.invoice_line_id =
account_invoice_line.id
join product_product
ON account_invoice_line.product_id = product_product.id
join product_template
ON product_product.product_tmpl_id = product_template.id
join product_category
ON product_template.categ_id = product_category.id
join product_uom
ON account_invoice_line.uom_id = product_uom.id;
report_stock_owner_invoice.xml
{
# The human-readable name of your module, displayed in the interface
'name': "",
# A more extensive description
'description': """
""",
'author': "Transcontinental",
# Categories can be used to filter modules in modules listing
# Check https://github.com/odoo/odoo/blob/master/openerp/addons/base/module/module_data.xml
# for the full list
'category': 'Warehouse',
'version': '0.1',
# Which modules must be installed for this one to work
'depends': [
'account',
],
# data files which are always installed
'data': [
'views/report_stock_owner_invoice.xml',
],
# data files which are only installed in "demonstration mode"
'demo': [],
}
I try to figure what is causing this. Anyone can help?