mirror of
https://github.com/bringout/oca-ocb-sale.git
synced 2026-04-27 17:52:01 +02:00
19.0 vanilla
This commit is contained in:
parent
79f83631d5
commit
73afc09215
6267 changed files with 1534193 additions and 1130106 deletions
|
|
@ -5,7 +5,7 @@ from odoo import api, models, _
|
|||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class PosInvoiceReport(models.AbstractModel):
|
||||
class ReportPoint_Of_SaleReport_Invoice(models.AbstractModel):
|
||||
_name = 'report.point_of_sale.report_invoice'
|
||||
_description = 'Point of Sale Invoice Report'
|
||||
|
||||
|
|
@ -22,7 +22,7 @@ class PosInvoiceReport(models.AbstractModel):
|
|||
if not_invoiced_orders_ids:
|
||||
not_invoiced_posorders = PosOrder.browse(not_invoiced_orders_ids)
|
||||
not_invoiced_orders_names = [a.name for a in not_invoiced_posorders]
|
||||
raise UserError(_('No link to an invoice for %s.') % ', '.join(not_invoiced_orders_names))
|
||||
raise UserError(_('No link to an invoice for %s.', ', '.join(not_invoiced_orders_names)))
|
||||
|
||||
return {
|
||||
'docs': self.env['account.move'].sudo().browse(ids_to_print),
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models, tools
|
||||
from odoo import fields, models, tools
|
||||
|
||||
|
||||
class PosOrderReport(models.Model):
|
||||
_name = "report.pos.order"
|
||||
class ReportPosOrder(models.Model):
|
||||
_name = 'report.pos.order'
|
||||
_description = "Point of Sale Orders Report"
|
||||
_auto = False
|
||||
_order = 'date desc'
|
||||
_rec_name = 'order_id'
|
||||
|
||||
date = fields.Datetime(string='Order Date', readonly=True)
|
||||
order_id = fields.Many2one('pos.order', string='Order', readonly=True)
|
||||
|
|
@ -16,42 +17,65 @@ class PosOrderReport(models.Model):
|
|||
product_id = fields.Many2one('product.product', string='Product', readonly=True)
|
||||
product_tmpl_id = fields.Many2one('product.template', string='Product Template', readonly=True)
|
||||
state = fields.Selection(
|
||||
[('draft', 'New'), ('paid', 'Paid'), ('done', 'Posted'),
|
||||
('invoiced', 'Invoiced'), ('cancel', 'Cancelled')],
|
||||
[('draft', 'New'), ('paid', 'Paid'), ('done', 'Posted'), ('cancel', 'Cancelled')],
|
||||
string='Status', readonly=True)
|
||||
user_id = fields.Many2one('res.users', string='User', readonly=True)
|
||||
price_total = fields.Float(string='Total Price', readonly=True)
|
||||
price_sub_total = fields.Float(string='Subtotal w/o discount', readonly=True)
|
||||
price_subtotal_excl = fields.Float(string='Subtotal w/o Tax', readonly=True)
|
||||
total_discount = fields.Float(string='Total Discount', readonly=True)
|
||||
average_price = fields.Float(string='Average Price', readonly=True, group_operator="avg")
|
||||
average_price = fields.Float(string='Average Price', readonly=True, aggregator="avg")
|
||||
company_id = fields.Many2one('res.company', string='Company', readonly=True)
|
||||
nbr_lines = fields.Integer(string='Sale Line Count', readonly=True)
|
||||
product_qty = fields.Integer(string='Product Quantity', readonly=True)
|
||||
journal_id = fields.Many2one('account.journal', string='Journal', readonly=True)
|
||||
delay_validation = fields.Integer(string='Delay Validation', readonly=True)
|
||||
product_categ_id = fields.Many2one('product.category', string='Product Category', readonly=True)
|
||||
pos_categ_id = fields.Many2one('pos.category', string='Point of Sale Category', readonly=True)
|
||||
invoiced = fields.Boolean(readonly=True)
|
||||
config_id = fields.Many2one('pos.config', string='Point of Sale', readonly=True)
|
||||
pos_categ_id = fields.Many2one('pos.category', string='PoS Category', readonly=True)
|
||||
pricelist_id = fields.Many2one('product.pricelist', string='Pricelist', readonly=True)
|
||||
session_id = fields.Many2one('pos.session', string='Session', readonly=True)
|
||||
margin = fields.Float(string='Margin', readonly=True)
|
||||
payment_method_id = fields.Many2one('pos.payment.method', string='Payment Method', readonly=True)
|
||||
|
||||
def _select(self):
|
||||
return """
|
||||
-- The purpose of this CTE is to map each "pos_order_line" to the "payment_method_id" corresponding to its "pos_order"
|
||||
-- considering we always show the first "payment_method_id"
|
||||
WITH payment_method_by_order_line AS (
|
||||
SELECT
|
||||
pol.id AS pos_order_line_id,
|
||||
pm.pos_order_id as pos_order_id,
|
||||
(array_agg(pm.payment_method_id ORDER BY pm.id ASC))[1] AS payment_method_id
|
||||
FROM pos_order_line pol
|
||||
LEFT JOIN pos_order po ON (po.id = pol.order_id)
|
||||
LEFT JOIN pos_payment pm ON (pm.pos_order_id=po.id)
|
||||
GROUP BY pol.id, pm.pos_order_id
|
||||
),
|
||||
first_pos_category AS (
|
||||
SELECT
|
||||
pt.id AS product_template_id,
|
||||
(array_agg(pc.id))[1] AS id
|
||||
FROM product_template pt
|
||||
LEFT JOIN pos_category_product_template_rel pcpt ON (pt.id = pcpt.product_template_id)
|
||||
LEFT JOIN pos_category pc ON (pcpt.pos_category_id = pc.id)
|
||||
GROUP BY pt.id
|
||||
)
|
||||
SELECT
|
||||
MIN(l.id) AS id,
|
||||
COUNT(*) AS nbr_lines,
|
||||
l.id AS id,
|
||||
1 AS nbr_lines, -- number of lines in order line is always 1
|
||||
s.date_order AS date,
|
||||
SUM(l.qty) AS product_qty,
|
||||
SUM(l.qty * l.price_unit / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END) AS price_sub_total,
|
||||
SUM(ROUND((l.price_subtotal_incl) / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END, cu.decimal_places)) AS price_total,
|
||||
SUM((l.qty * l.price_unit) * (l.discount / 100) / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END) AS total_discount,
|
||||
ROUND((l.price_subtotal * CASE WHEN s.is_refund THEN -1 ELSE 1 END) / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END, cu.decimal_places) AS price_subtotal_excl,
|
||||
l.qty AS product_qty,
|
||||
l.qty * l.price_unit / COALESCE(NULLIF(s.currency_rate, 0), 1.0) AS price_sub_total,
|
||||
ROUND((l.price_subtotal_incl * CASE WHEN s.is_refund THEN -1 ELSE 1 END) / COALESCE(NULLIF(s.currency_rate, 0), 1.0), cu.decimal_places) AS price_total,
|
||||
(l.qty * l.price_unit) * (l.discount / 100) / COALESCE(NULLIF(s.currency_rate, 0), 1.0) AS total_discount,
|
||||
CASE
|
||||
WHEN SUM(l.qty * u.factor) = 0 THEN NULL
|
||||
ELSE (SUM(l.qty*l.price_unit / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END)/SUM(l.qty * u.factor))::decimal
|
||||
WHEN l.qty * u.factor = 0 THEN NULL
|
||||
ELSE (l.qty*l.price_unit / COALESCE(NULLIF(s.currency_rate, 0), 1.0))/(l.qty * u.factor)::decimal
|
||||
END AS average_price,
|
||||
SUM(cast(to_char(date_trunc('day',s.date_order) - date_trunc('day',s.create_date),'DD') AS INT)) AS delay_validation,
|
||||
cast(to_char(date_trunc('day',s.date_order) - date_trunc('day',s.create_date),'DD') AS INT) AS delay_validation,
|
||||
s.id as order_id,
|
||||
s.partner_id AS partner_id,
|
||||
s.state AS state,
|
||||
|
|
@ -62,11 +86,13 @@ class PosOrderReport(models.Model):
|
|||
pt.categ_id AS product_categ_id,
|
||||
p.product_tmpl_id,
|
||||
ps.config_id,
|
||||
pt.pos_categ_id,
|
||||
s.pricelist_id,
|
||||
s.session_id,
|
||||
s.account_move IS NOT NULL AS invoiced,
|
||||
SUM(l.price_subtotal - COALESCE(l.total_cost,0) / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END) AS margin
|
||||
(l.price_subtotal * CASE WHEN s.is_refund THEN -1 ELSE 1 END) - COALESCE(l.total_cost,0) / COALESCE(NULLIF(s.currency_rate, 0), 1.0) AS margin,
|
||||
pm.payment_method_id AS payment_method_id,
|
||||
fpc.id AS pos_categ_id
|
||||
|
||||
"""
|
||||
|
||||
def _from(self):
|
||||
|
|
@ -79,27 +105,20 @@ class PosOrderReport(models.Model):
|
|||
LEFT JOIN pos_session ps ON (s.session_id=ps.id)
|
||||
LEFT JOIN res_company co ON (s.company_id=co.id)
|
||||
LEFT JOIN res_currency cu ON (co.currency_id=cu.id)
|
||||
LEFT JOIN payment_method_by_order_line pm ON (pm.pos_order_line_id=l.id)
|
||||
LEFT JOIN pos_payment_method ppm ON (pm.payment_method_id=ppm.id)
|
||||
LEFT JOIN first_pos_category fpc ON (pt.id = fpc.product_template_id)
|
||||
"""
|
||||
|
||||
def _group_by(self):
|
||||
return """
|
||||
GROUP BY
|
||||
s.id, s.date_order, s.partner_id,s.state, pt.categ_id,
|
||||
s.user_id, s.company_id, s.sale_journal,
|
||||
s.pricelist_id, s.account_move, s.create_date, s.session_id,
|
||||
l.product_id,
|
||||
pt.categ_id, pt.pos_categ_id,
|
||||
p.product_tmpl_id,
|
||||
ps.config_id
|
||||
"""
|
||||
return ""
|
||||
|
||||
def init(self):
|
||||
tools.drop_view_if_exists(self._cr, self._table)
|
||||
self._cr.execute("""
|
||||
tools.drop_view_if_exists(self.env.cr, self._table)
|
||||
self.env.cr.execute("""
|
||||
CREATE OR REPLACE VIEW %s AS (
|
||||
%s
|
||||
%s
|
||||
%s
|
||||
)
|
||||
""" % (self._table, self._select(), self._from(), self._group_by())
|
||||
""" % (self._table, self._select(), self._from())
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue