Skip to content

Commit

Permalink
[IMP] sale_start_end_dates: add fields in sale.report
Browse files Browse the repository at this point in the history
Inherit standalone sale.order.line views
  • Loading branch information
alexis-via committed Dec 18, 2024
1 parent d830b4c commit 4492c86
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 1 deletion.
1 change: 1 addition & 0 deletions sale_start_end_dates/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import models
from . import reports
6 changes: 5 additions & 1 deletion sale_start_end_dates/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
"maintainers": ["alexis-via"],
"website": "https://github.com/OCA/sale-workflow",
"depends": ["account_invoice_start_end_dates", "sale"],
"data": ["views/sale_order.xml"],
"data": [
"views/sale_order.xml",
"views/sale_order_line.xml",
"reports/sale_report.xml",
],
"installable": True,
}
1 change: 1 addition & 0 deletions sale_start_end_dates/reports/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import sale_report
25 changes: 25 additions & 0 deletions sale_start_end_dates/reports/sale_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2024 Akretion France (https://www.akretion.com/)
# @author Alexis de Lattre <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class SaleReport(models.Model):
_inherit = "sale.report"

start_date = fields.Date(readonly=True)
end_date = fields.Date(readonly=True)
number_of_days = fields.Integer(readonly=True)

def _select_additional_fields(self):
res = super()._select_additional_fields()
res["start_date"] = "l.start_date"
res["end_date"] = "l.end_date"
res["number_of_days"] = "l.number_of_days"
return res

def _group_by_sale(self):
sql = super()._group_by_sale()
sql = f"{sql}, l.start_date, l.end_date, l.number_of_days"
return sql
20 changes: 20 additions & 0 deletions sale_start_end_dates/reports/sale_report.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2024 Akretion France (https://www.akretion.com/)
@author: Alexis de Lattre <[email protected]>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="sale_report_view_tree" model="ir.ui.view">
<field name="model">sale.report</field>
<field name="inherit_id" ref="sale.sale_report_view_tree" />
<field name="arch" type="xml">
<field name="product_uom_qty" position="before">
<field name="start_date" optional="hide" />
<field name="end_date" optional="hide" />
<field name="number_of_days" optional="hide" invisible="not start_date"/>
</field>
</field>
</record>

</odoo>
60 changes: 60 additions & 0 deletions sale_start_end_dates/views/sale_order_line.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2024 Akretion France (https://www.akretion.com/)
@author Alexis de Lattre <[email protected]>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="view_order_line_tree" model="ir.ui.view">
<field name="model">sale.order.line</field>
<field name="inherit_id" ref="sale.view_order_line_tree" />
<field name="arch" type="xml">
<field name="name" position="after">
<field
name="start_date"
required="must_have_dates"
invisible="not must_have_dates"
optional="show"
/>
<field
name="end_date"
required="must_have_dates"
invisible="not must_have_dates"
optional="show"
/>
<field
name="number_of_days"
required="must_have_dates"
invisible="not must_have_dates"
optional="hide"
/>
<field name="must_have_dates" column_invisible="1" />
</field>
</field>
</record>
<record id="sale_order_line_view_form_readonly" model="ir.ui.view">
<field name="model">sale.order.line</field>
<field name="inherit_id" ref="sale.sale_order_line_view_form_readonly" />
<field name="arch" type="xml">
<field name="name" position="after">
<field
name="start_date"
required="must_have_dates"
invisible="not must_have_dates"
/>
<field
name="end_date"
required="must_have_dates"
invisible="not must_have_dates"
/>
<field
name="number_of_days"
required="must_have_dates"
invisible="not must_have_dates"
/>
<field name="must_have_dates" column_invisible="1" />
</field>
</field>
</record>

</odoo>

0 comments on commit 4492c86

Please sign in to comment.