Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][MIG]sale_order_invoice_date:Migration to 15.0 #203

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions sale_order_invoice_date/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
=======================
Sale Order Invoice Date
=======================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--reporting-lightgray.png?logo=github
:target: https://github.com/OCA/sale-reporting/tree/14.0/sale_order_invoice_date
:alt: OCA/sale-reporting
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sale-reporting-14-0/sale-reporting-14-0-sale_order_invoice_date
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/148/14.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

Display the invoice date on Sales Order analysis reports.

The invoice date is considered to be the latest invoice date linked to fully
invoiced sales.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-reporting/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/sale-reporting/issues/new?body=module:%20sale_order_invoice_date%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Camptocamp

Contributors
~~~~~~~~~~~~

* `Camptocamp <https://www.camptocamp.com>`_

* Iván Todorovich <[email protected]>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-ivantodorovich| image:: https://github.com/ivantodorovich.png?size=40px
:target: https://github.com/ivantodorovich
:alt: ivantodorovich

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-ivantodorovich|

This module is part of the `OCA/sale-reporting <https://github.com/OCA/sale-reporting/tree/14.0/sale_order_invoice_date>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions sale_order_invoice_date/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import models
from . import reports
from .hooks import pre_init_hook
17 changes: 17 additions & 0 deletions sale_order_invoice_date/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2022 Camptocamp SA (https://www.camptocamp.com).
# @author Iván Todorovich <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Sale Order Invoice Date",
"summary": "Display the invoice date on Sales Order analysis reports",
"version": "15.0.1.0.0",
"author": "Camptocamp, Odoo Community Association (OCA)",
"maintainers": ["ivantodorovich"],
"website": "https://github.com/OCA/sale-reporting",
"license": "AGPL-3",
"category": "Sales",
"depends": ["sale"],
"data": ["reports/sale_report.xml"],
"pre_init_hook": "pre_init_hook",
}
48 changes: 48 additions & 0 deletions sale_order_invoice_date/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2022 Camptocamp SA (https://www.camptocamp.com).
# @author Iván Todorovich <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import logging

from odoo.tools import column_exists, create_column

_logger = logging.getLogger(__name__)


def pre_init_hook(cr):
if not column_exists(cr, "sale_order_line", "invoice_date"):
create_column(cr, "sale_order_line", "invoice_date", "date")
if not column_exists(cr, "sale_order", "invoice_date"):
create_column(cr, "sale_order", "invoice_date", "date")
_logger.info("Initializing computed values for sale_order_line.invoice_date")
cr.execute(
"""
WITH sol AS (
SELECT sol.id AS id, max(move.invoice_date) AS invoice_date
FROM sale_order_line_invoice_rel rel
INNER JOIN sale_order_line sol ON rel.order_line_id = sol.id
INNER JOIN account_move_line aml ON rel.invoice_line_id = aml.id
INNER JOIN account_move move ON aml.move_id = move.id
WHERE sol.invoice_status = 'invoiced'
GROUP BY sol.id
)
UPDATE sale_order_line
SET invoice_date = sol.invoice_date
FROM sol WHERE sale_order_line.id = sol.id
"""
)
_logger.info("Initializing computed values for sale_order.invoice_date")
cr.execute(
"""
WITH so AS (
SELECT so.id AS id, max(sol.invoice_date) AS invoice_date
FROM sale_order_line sol
INNER JOIN sale_order so ON sol.order_id = so.id
WHERE so.invoice_status = 'invoiced' AND sol.invoice_date IS NOT NULL
GROUP BY so.id
)
UPDATE sale_order
SET invoice_date = so.invoice_date
FROM so WHERE sale_order.id = so.id
"""
)
61 changes: 61 additions & 0 deletions sale_order_invoice_date/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_order_invoice_date
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-06-09 19:45+0000\n"
"PO-Revision-Date: 2022-06-09 19:45+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: sale_order_invoice_date
#: model:ir.model.fields,field_description:sale_order_invoice_date.field_sale_order__display_name
#: model:ir.model.fields,field_description:sale_order_invoice_date.field_sale_order_line__display_name
#: model:ir.model.fields,field_description:sale_order_invoice_date.field_sale_report__display_name
msgid "Display Name"
msgstr "Nom affiché"

#. module: sale_order_invoice_date
#: model:ir.model.fields,field_description:sale_order_invoice_date.field_sale_order__id
#: model:ir.model.fields,field_description:sale_order_invoice_date.field_sale_order_line__id
#: model:ir.model.fields,field_description:sale_order_invoice_date.field_sale_report__id
msgid "ID"
msgstr ""

#. module: sale_order_invoice_date
#: model:ir.model.fields,field_description:sale_order_invoice_date.field_sale_order__invoice_date
#: model:ir.model.fields,field_description:sale_order_invoice_date.field_sale_order_line__invoice_date
#: model:ir.model.fields,field_description:sale_order_invoice_date.field_sale_report__invoice_date
#: model_terms:ir.ui.view,arch_db:sale_order_invoice_date.view_order_product_search
msgid "Invoice Date"
msgstr "Date de facturation"

#. module: sale_order_invoice_date
#: model:ir.model.fields,field_description:sale_order_invoice_date.field_sale_order____last_update
#: model:ir.model.fields,field_description:sale_order_invoice_date.field_sale_order_line____last_update
#: model:ir.model.fields,field_description:sale_order_invoice_date.field_sale_report____last_update
msgid "Last Modified on"
msgstr "Dernière modification le"

#. module: sale_order_invoice_date
#: model:ir.model,name:sale_order_invoice_date.model_sale_report
msgid "Sales Analysis Report"
msgstr "Rapport d'analyse des ventes"

#. module: sale_order_invoice_date
#: model:ir.model,name:sale_order_invoice_date.model_sale_order
msgid "Sales Order"
msgstr "Bon de commande"

#. module: sale_order_invoice_date
#: model:ir.model,name:sale_order_invoice_date.model_sale_order_line
msgid "Sales Order Line"
msgstr "Ligne de bons de commande"
58 changes: 58 additions & 0 deletions sale_order_invoice_date/i18n/sale_order_invoice_date.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_order_invoice_date
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: sale_order_invoice_date
#: model:ir.model.fields,field_description:sale_order_invoice_date.field_sale_order__display_name
#: model:ir.model.fields,field_description:sale_order_invoice_date.field_sale_order_line__display_name
#: model:ir.model.fields,field_description:sale_order_invoice_date.field_sale_report__display_name
msgid "Display Name"
msgstr ""

#. module: sale_order_invoice_date
#: model:ir.model.fields,field_description:sale_order_invoice_date.field_sale_order__id
#: model:ir.model.fields,field_description:sale_order_invoice_date.field_sale_order_line__id
#: model:ir.model.fields,field_description:sale_order_invoice_date.field_sale_report__id
msgid "ID"
msgstr ""

#. module: sale_order_invoice_date
#: model:ir.model.fields,field_description:sale_order_invoice_date.field_sale_order__invoice_date
#: model:ir.model.fields,field_description:sale_order_invoice_date.field_sale_order_line__invoice_date
#: model:ir.model.fields,field_description:sale_order_invoice_date.field_sale_report__invoice_date
#: model_terms:ir.ui.view,arch_db:sale_order_invoice_date.view_order_product_search
msgid "Invoice Date"
msgstr ""

#. module: sale_order_invoice_date
#: model:ir.model.fields,field_description:sale_order_invoice_date.field_sale_order____last_update
#: model:ir.model.fields,field_description:sale_order_invoice_date.field_sale_order_line____last_update
#: model:ir.model.fields,field_description:sale_order_invoice_date.field_sale_report____last_update
msgid "Last Modified on"
msgstr ""

#. module: sale_order_invoice_date
#: model:ir.model,name:sale_order_invoice_date.model_sale_report
msgid "Sales Analysis Report"
msgstr ""

#. module: sale_order_invoice_date
#: model:ir.model,name:sale_order_invoice_date.model_sale_order
msgid "Sales Order"
msgstr ""

#. module: sale_order_invoice_date
#: model:ir.model,name:sale_order_invoice_date.model_sale_order_line
msgid "Sales Order Line"
msgstr ""
2 changes: 2 additions & 0 deletions sale_order_invoice_date/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import sale_order
from . import sale_order_line
25 changes: 25 additions & 0 deletions sale_order_invoice_date/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2022 Camptocamp SA (https://www.camptocamp.com).
# @author Iván Todorovich <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


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

invoice_date = fields.Date(compute="_compute_invoice_date", store=True)

@api.depends("order_line.invoice_date")
def _compute_invoice_date(self):
data = {}
invoiced = self.filtered(lambda rec: rec.invoice_status == "invoiced")
if invoiced.ids:
groups = self.env["sale.order.line"].read_group(
domain=[("order_id", "in", invoiced.ids)],
fields=["order_id", "invoice_date:max"],
groupby=["order_id"],
)
data = {g["order_id"][0]: g["invoice_date"] for g in groups}
for rec in self:
rec.invoice_date = data.get(rec.id, False)
22 changes: 22 additions & 0 deletions sale_order_invoice_date/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2022 Camptocamp SA (https://www.camptocamp.com).
# @author Iván Todorovich <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class SaleOrderLine(models.Model):
_inherit = "sale.order.line"

invoice_date = fields.Date(compute="_compute_invoice_date", store=True)

@api.depends("invoice_status", "invoice_lines.move_id.invoice_date")
def _compute_invoice_date(self):
invoiced = self.filtered(lambda rec: rec.invoice_status == "invoiced")
not_invoiced = self - invoiced
not_invoiced.invoice_date = False
for rec in invoiced:
rec.invoice_date = max(
(d for d in rec.invoice_lines.move_id.mapped("invoice_date") if d),
default=False,
)
3 changes: 3 additions & 0 deletions sale_order_invoice_date/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `Camptocamp <https://www.camptocamp.com>`_

* Iván Todorovich <[email protected]>
4 changes: 4 additions & 0 deletions sale_order_invoice_date/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Display the invoice date on Sales Order analysis reports.

The invoice date is considered to be the latest invoice date linked to fully
invoiced sales.
1 change: 1 addition & 0 deletions sale_order_invoice_date/reports/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import sale_report
19 changes: 19 additions & 0 deletions sale_order_invoice_date/reports/sale_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2022 Camptocamp SA (https://www.camptocamp.com).
# @author Iván Todorovich <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


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

invoice_date = fields.Date(readonly=True)

def _select_sale(self, fields=None):
res = super()._select_sale(fields=fields)
return f"{res}, l.invoice_date"

def _group_by_sale(self, groupby=""):
res = super()._group_by_sale(groupby=groupby)
return f"{res}, l.invoice_date"
31 changes: 31 additions & 0 deletions sale_order_invoice_date/reports/sale_report.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2022 Camptocamp SA (https://www.camptocamp.com).
@author Iván Todorovich <[email protected]>
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->
<odoo>

<record id="view_order_product_search" model="ir.ui.view">
<field name="model">sale.report</field>
<field name="inherit_id" ref="sale.view_order_product_search" />
<field name="priority" eval="30" />
<field name="arch" type="xml">
<filter name="filter_date" position="after">
<filter
name="filter_invoice_date"
date="invoice_date"
default_period="this_month"
/>
</filter>
<filter name="date" position="after">
<filter
string="Invoice Date"
name="invoice_date"
context="{'group_by': 'invoice_date'}"
/>
</filter>
</field>
</record>

</odoo>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading