Skip to content

Commit ce6d2db

Browse files
committed
[IMP] Consistent prices and subtotal in SO
1 parent 091ca60 commit ce6d2db

File tree

5 files changed

+77
-3
lines changed

5 files changed

+77
-3
lines changed

grap_change_views_sale/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"delivery",
1616
"sale_margin",
1717
"product_margin_classification",
18+
"grap_qweb_report",
1819
],
1920
"data": [
2021
"views/menu.xml",

grap_change_views_sale/views/view_sale_order.xml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,22 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
4242
<xpath expr="//field[@name='order_line']/tree/field[@name='discount']" position="attributes">
4343
<attribute name="string">Disc 1 (%)</attribute>
4444
</xpath>
45-
<xpath expr="//field[@name='order_line']/tree/field[@name='price_subtotal']" position="attributes">
46-
<attribute name="string">S.T.</attribute>
45+
46+
<field name="fiscal_position_id" position="after">
47+
<field name="price_unit_include_taxes" invisible="1"/>
48+
</field>
49+
<!-- Reset annoying groups -->
50+
<xpath expr="//field[@name='order_line']/tree/field[@name='price_total']" position="attributes">
51+
<attribute name="groups">account.group_show_line_subtotals_tax_excluded</attribute>
52+
</xpath>
53+
<!-- Display the right column -->
54+
<xpath expr="//field[@name='order_line']/tree/field[@name='price_subtotal']" position="replace">
55+
<field name="price_subtotal" string="Sous-Total (HT)" attrs="{'column_invisible': [('parent.price_unit_include_taxes', '=', True)]}"/>
4756
</xpath>
57+
<xpath expr="//field[@name='order_line']/tree/field[@name='price_total']" position="replace">
58+
<field name="price_total" string="Sous-Total (TTC)" attrs="{'column_invisible': [('parent.price_unit_include_taxes', '=', False)]}"/>
59+
</xpath>
60+
4861
<xpath expr="//field[@name='order_line']/tree/field[@name='tax_id']" position="attributes">
4962
<attribute name="attrs">{'readonly': 1}</attribute>
5063
<attribute name="force_save">1</attribute>

grap_qweb_report/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"report/qweb_template_product_product_barcode.xml",
3232
"report/qweb_template_layout_standard.xml",
3333
"report/qweb_template_account_invoice.xml",
34+
"report/qweb_template_sale_order.xml",
3435
"report/qweb_template_stock_deliveryslip.xml",
3536
"report/qweb_template_stock_inventory.xml",
3637
"report/qweb_pricetag_square_small.xml",

grap_qweb_report/models/sale_order.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,37 @@
22
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
33
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
44

5-
from odoo import models
5+
from odoo import api, fields, models
66

77

88
class SaleOrder(models.Model):
99
_inherit = "sale.order"
1010

11+
price_unit_include_taxes = fields.Boolean(
12+
string="Subtotal w / wo taxes",
13+
compute="_compute_price_unit_include_taxes",
14+
default=False,
15+
)
16+
1117
def action_invoice_create(self, grouped=False, final=False):
1218
if not grouped and len(self) > 1:
1319
return super(
1420
SaleOrder, self.with_context(add_picking_date=True)
1521
).action_invoice_create(grouped=grouped, final=final)
1622
return super().action_invoice_create(grouped=grouped, final=final)
23+
24+
@api.depends("fiscal_position_id")
25+
def _compute_price_unit_include_taxes(self):
26+
# Check if fiscal_position is w ou wo taxes (just checking first line)
27+
for invoice in self:
28+
# Check if there is a fiscal_position
29+
try:
30+
tax_dest = invoice.fiscal_position_id.tax_ids[0].tax_dest_id
31+
# No fiscal position → wo taxes
32+
except IndexError:
33+
invoice.price_unit_include_taxes = False
34+
else:
35+
if tax_dest.price_include:
36+
invoice.price_unit_include_taxes = True
37+
else:
38+
invoice.price_unit_include_taxes = False
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright (C) 2018 - Today: GRAP (http://www.grap.coop)
4+
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
5+
@author: Quentin DUPONT ([email protected])
6+
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
7+
-->
8+
<odoo>
9+
10+
<template id="template_sale_order" inherit_id="sale.report_saleorder_document">
11+
12+
<!-- Colonne Prix Unitaire : Pas de HT ou TTC dans le nom car ça depend des lignes -->
13+
<xpath expr="//th[@name='th_priceunit']" position="replace">
14+
<th name="th_priceunit" t-attf-class="text-right {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}"><span>Prix&#160;unitaire</span></th>
15+
</xpath>
16+
17+
<!-- Colonne Sous-Total : Choix HT ou TTC selon facture sur Odoo -->
18+
<xpath expr="//th[@name='th_subtotal']" position="replace">
19+
<th t-if="doc.price_unit_include_taxes" name="th_subtotal" class="text-right">
20+
<span>S.T&#160;(TTC)</span>
21+
</th>
22+
<th t-else="" name="th_subtotal" class="text-right">
23+
<span>S.T&#160;(HT)</span>
24+
</th>
25+
</xpath>
26+
<xpath expr="//td[@name='td_subtotal']" position="replace">
27+
<td t-if="doc.price_unit_include_taxes" class="text-right">
28+
<span t-field="line.price_total"/>
29+
</td>
30+
<td t-else="" class="text-right">
31+
<span t-field="line.price_subtotal"/>
32+
</td>
33+
</xpath>
34+
35+
</template>
36+
37+
</odoo>

0 commit comments

Comments
 (0)