Skip to content
Open
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
146 changes: 146 additions & 0 deletions mis_builder_total_committed_purchase/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
====================================
MIS Builder Total Committed Purchase
====================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:d7d370ad1866bc789c9ee7a5d27cc7e752740f9f6b4807a05f96b668e0c55c07
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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%2Fmis--builder--contrib-lightgray.png?logo=github
:target: https://github.com/OCA/mis-builder-contrib/tree/17.0/mis_builder_total_committed_purchase
:alt: OCA/mis-builder-contrib
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/mis-builder-contrib-17-0/mis-builder-contrib-17-0-mis_builder_total_committed_purchase
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/mis-builder-contrib&target_branch=17.0
:alt: Try me on Runboat

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

Addon to create a alternative source based on all purchase order lines
with MIS Builder : all the purchase orders that are not in draft or
cancelled state are taken into account.

The account_id of the committed purchase bases itself on the product's
account_id if set

- If not, it bases itself on the product_category's account_id if set

- If not, it bases itself on the first set account_id on five
generations of parent_category

- If none of them is set, it bases itself on the default value for
new resources

- Finally if it's not set, the account_id is set to 0

**Needed improvement :**

It would be better if the account_id tried to base itself on all the
generations of parent_category, as long as it is set.

**Table of contents**

.. contents::
:local:

Usage
=====

This module provides a committed purchase view model, showing all
purchases confirmed

Known issues / Roadmap
======================

The mis_builder
`roadmap <https://github.com/OCA/mis-builder/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement>`__
and `known
issues <https://github.com/OCA/mis-builder/issues?q=is%3Aopen+is%3Aissue+label%3Abug>`__
can be found on github.

Changelog
=========

15.0.1.0.1 (2022-11-24)
-----------------------

**Features**

- Add the product_id to the mis_builder_total_committed_purchase.

15.0.1.0.0 (2022-08-30)
-----------------------

**Features**

- Add an addon to create a alternative source based on PO lines with MIS
Builder, based on (`MIS Builder
Demo <https://github.com/OCA/mis-builder/tree/15.0/mis_builder_demo>`__)
addon.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/mis-builder-contrib/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/mis-builder-contrib/issues/new?body=module:%20mis_builder_total_committed_purchase%0Aversion:%2017.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
-------

* ACSONE SA/NV
* Camptocamp

Contributors
------------

- Stéphane Bidoul <stephane.bidoul@acsone.eu>

- Arnaud Pineux <arnaud.pineux@acsone.eu>

- Camille Morand <camille.morand@camptocamp.com>

- `Trobz <https://trobz.com>`__:

- Dzung Tran <dungtd@trobz.com>

Other credits
-------------

The migration of this module from 15.0 to 16.0 was financially supported
by Camptocamp

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.

This module is part of the `OCA/mis-builder-contrib <https://github.com/OCA/mis-builder-contrib/tree/17.0/mis_builder_total_committed_purchase>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
6 changes: 6 additions & 0 deletions mis_builder_total_committed_purchase/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from . import models


def uninstall_hook(cr, registry):
# drop relation view manually because Odoo does not know about it
cr.execute("DROP VIEW IF EXISTS mis_total_committed_purchase_tag_rel")
21 changes: 21 additions & 0 deletions mis_builder_total_committed_purchase/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2017-2018 ACSONE SA/NV
# Copyright 2022 Camptocamp SA (https://www.camptocamp.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "MIS Builder Total Committed Purchase",
"summary": """Addon to create a alternative source based on all purchase order line
with MIS Builder.""",
"version": "17.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV, Camptocamp, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/mis-builder-contrib",
"depends": ["mis_builder", "purchase"],
"data": [
"data/mis_total_committed_purchase.sql",
"data/mis_total_committed_purchase_analytic_account_rel.sql",
"security/mis_total_committed_purchase.xml",
"views/mis_total_committed_purchase.xml",
],
"installable": True,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
CREATE OR REPLACE VIEW mis_total_committed_purchase AS (
SELECT ROW_NUMBER() OVER() AS id, mis_total_committed_purchase.* FROM (
WITH currency_rate as (
SELECT
r.currency_id,
COALESCE(r.company_id, c.id) as company_id,
r.rate,
r.name AS date_start,
(SELECT name FROM res_currency_rate r2
WHERE r2.name > r.name AND
r2.currency_id = r.currency_id AND
(r2.company_id is null or r2.company_id = c.id)
ORDER BY r2.name ASC
LIMIT 1) AS date_end
FROM res_currency_rate r
JOIN res_company c ON (r.company_id is null or r.company_id = c.id)
),
pol_analytic AS (
SELECT
id,
jsonb_object_keys(analytic_distribution)::INTEGER AS analytic_account_id,
(analytic_distribution -> jsonb_object_keys(analytic_distribution))::NUMERIC AS analytic_amount
FROM purchase_order_line
)

/* ALL CONFIRMED PURCHASES */
SELECT
pol.company_id AS company_id,
pol.name AS name,
po.date_planned::date as date,
pol.product_id as product_id,
pol.order_id as purchase_order_id,
pol.id AS res_id,
'purchase.order.line' AS res_model,
CASE
WHEN (cast(split_part(ip.value_reference, ',', 2) AS INTEGER) IS NOT NULL) THEN cast(split_part(ip.value_reference, ',', 2) AS INTEGER)
WHEN (cast(split_part(ipc1.value_reference, ',', 2) AS INTEGER) IS NOT NULL) THEN cast(split_part(ipc1.value_reference, ',', 2) AS INTEGER)
WHEN (cast(split_part(ipc2.value_reference, ',', 2) AS INTEGER) IS NOT NULL) THEN cast(split_part(ipc2.value_reference, ',', 2) AS INTEGER)
WHEN (cast(split_part(ipc3.value_reference, ',', 2) AS INTEGER) IS NOT NULL) THEN cast(split_part(ipc3.value_reference, ',', 2) AS INTEGER)
WHEN (cast(split_part(ipc4.value_reference, ',', 2) AS INTEGER) IS NOT NULL) THEN cast(split_part(ipc4.value_reference, ',', 2) AS INTEGER)
WHEN (cast(split_part(ipc5.value_reference, ',', 2) AS INTEGER) IS NOT NULL) THEN cast(split_part(ipc5.value_reference, ',', 2) AS INTEGER)
WHEN (cast(split_part(ipd.value_reference, ',', 2) AS INTEGER) IS NOT NULL) THEN cast(split_part(ipd.value_reference, ',', 2) AS INTEGER)
ELSE cast(NULL AS INTEGER)
END AS account_id,

CASE
WHEN
aaa.id = pol_analytic.analytic_account_id
AND (pol.price_unit / COALESCE(cur.rate, 1.0) * pol.product_qty)::decimal(16,2) >= 0.0
THEN (pol.price_unit / COALESCE(cur.rate, 1.0) * pol.product_qty)::decimal(16,2)
* COALESCE(pol_analytic.analytic_amount, 100.0) / 100.0
ELSE 0.0
END AS debit,

CASE
WHEN
aaa.id = pol_analytic.analytic_account_id
AND (pol.price_unit / COALESCE(cur.rate, 1.0) * pol.product_qty)::decimal(16,2) < 0
THEN (pol.price_unit / COALESCE(cur.rate, 1.0) * pol.product_qty)::decimal(16,2)
* COALESCE(pol_analytic.analytic_amount, 100.0) / 100.0
ELSE 0.0
END AS credit,
pol_analytic.analytic_account_id

FROM purchase_order_line pol
LEFT JOIN pol_analytic ON pol.id = pol_analytic.id
LEFT JOIN account_analytic_account aaa ON pol_analytic.analytic_account_id = aaa.id
LEFT JOIN purchase_order po on po.id = pol.order_id
LEFT JOIN product_product pp ON pp.id = pol.product_id
LEFT JOIN product_template pt ON pt.id = pp.product_tmpl_id
LEFT JOIN product_category pc1 ON pc1.id = pt.categ_id
LEFT JOIN product_category pc2 ON pc2.id = pc1.parent_id
LEFT JOIN product_category pc3 ON pc3.id = pc2.parent_id
LEFT JOIN product_category pc4 ON pc4.id = pc3.parent_id
LEFT JOIN product_category pc5 ON pc5.id = pc4.parent_id
LEFT JOIN ir_property ip ON ip.name = 'property_account_expense_id' AND ip.type='many2one' AND ip.res_id ='product.template,' || pt.id
LEFT JOIN ir_property ipc1 ON ipc1.name = 'property_account_expense_categ_id' AND ipc1.type='many2one' AND ipc1.res_id ='product.category,' || pc1.id
LEFT JOIN ir_property ipc2 ON ipc2.name = 'property_account_expense_categ_id' AND ipc2.type='many2one' AND ipc2.res_id ='product.category,' || pc2.id
LEFT JOIN ir_property ipc3 ON ipc3.name = 'property_account_expense_categ_id' AND ipc3.type='many2one' AND ipc3.res_id ='product.category,' || pc3.id
LEFT JOIN ir_property ipc4 ON ipc4.name = 'property_account_expense_categ_id' AND ipc4.type='many2one' AND ipc4.res_id ='product.category,' || pc4.id
LEFT JOIN ir_property ipc5 ON ipc5.name = 'property_account_expense_categ_id' AND ipc5.type='many2one' AND ipc5.res_id ='product.category,' || pc5.id
LEFT JOIN ir_property ipd ON ipd.name = 'property_account_expense_categ_id' AND ipd.type='many2one' AND (ipd.res_id IS NULL OR ipd.res_id = '') AND ipd.company_id=po.company_id
LEFT JOIN currency_rate cur on (cur.currency_id = po.currency_id and
cur.company_id = po.company_id and
cur.date_start <= coalesce(po.date_order, now()) and
(cur.date_end is null or cur.date_end > coalesce(po.date_order, now())))
WHERE po.state != 'cancel' AND po.state != 'draft'
) AS mis_total_committed_purchase
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
CREATE OR REPLACE VIEW mis_total_committed_purchase_analytic_account_rel AS(
SELECT
po_mcp.id AS mis_total_committed_purchase_id,
jsonb_object_keys(po_rel.analytic_distribution)::INTEGER
AS analytic_account_id

FROM purchase_order_line AS po_rel
INNER JOIN mis_total_committed_purchase AS po_mcp ON
po_mcp.res_id = po_rel.id

WHERE CAST(po_mcp.res_model AS VARCHAR) = 'purchase.order.line'

UNION ALL

SELECT
inv_mcp.id AS mis_total_committed_purchase_id,
jsonb_object_keys(inv_rel.analytic_distribution)::INTEGER
AS analytic_account_id

FROM account_move_line AS inv_rel
INNER JOIN mis_total_committed_purchase AS inv_mcp ON
inv_mcp.res_id = inv_rel.id

WHERE CAST(inv_mcp.res_model AS VARCHAR) = 'account.move.line'
)
82 changes: 82 additions & 0 deletions mis_builder_total_committed_purchase/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mis_builder_total_committed_purchase
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2024-09-12 09:06+0000\n"
"Last-Translator: mymage <stefano.consolaro@mymage.it>\n"
"Language-Team: none\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 5.6.2\n"

#. module: mis_builder_total_committed_purchase
#: model:ir.model.fields,field_description:mis_builder_total_committed_purchase.field_mis_total_committed_purchase__account_id
msgid "Account"
msgstr "Conto"

#. module: mis_builder_total_committed_purchase
#: model:ir.model.fields,field_description:mis_builder_total_committed_purchase.field_mis_total_committed_purchase__analytic_account_id
msgid "Analytic Account"
msgstr "Conto analitico"

#. module: mis_builder_total_committed_purchase
#: model:ir.model.fields,field_description:mis_builder_total_committed_purchase.field_mis_total_committed_purchase__company_id
msgid "Company"
msgstr "Azienda"

#. module: mis_builder_total_committed_purchase
#: model:ir.model.fields,field_description:mis_builder_total_committed_purchase.field_mis_total_committed_purchase__credit
msgid "Credit"
msgstr "Credito"

#. module: mis_builder_total_committed_purchase
#: model:ir.model.fields,field_description:mis_builder_total_committed_purchase.field_mis_total_committed_purchase__date
msgid "Date"
msgstr "Data"

#. module: mis_builder_total_committed_purchase
#: model:ir.model.fields,field_description:mis_builder_total_committed_purchase.field_mis_total_committed_purchase__debit
msgid "Debit"
msgstr "Debito"

#. module: mis_builder_total_committed_purchase
#: model:ir.model.fields,field_description:mis_builder_total_committed_purchase.field_mis_total_committed_purchase__display_name
msgid "Display Name"
msgstr "Nome visualizzato"

#. module: mis_builder_total_committed_purchase
#: model:ir.model.fields,field_description:mis_builder_total_committed_purchase.field_mis_total_committed_purchase__id
msgid "ID"
msgstr "ID"

#. module: mis_builder_total_committed_purchase
#: model:ir.model.fields,field_description:mis_builder_total_committed_purchase.field_mis_total_committed_purchase____last_update
msgid "Last Modified on"
msgstr "Ultima modifica il"

#. module: mis_builder_total_committed_purchase
#: model:ir.model,name:mis_builder_total_committed_purchase.model_mis_total_committed_purchase
msgid "MIS Total Purchase Commitment"
msgstr "Impegno acquisto totale MIS"

#. module: mis_builder_total_committed_purchase
#: model:ir.model.fields,field_description:mis_builder_total_committed_purchase.field_mis_total_committed_purchase__name
msgid "Name"
msgstr "Nome"

#. module: mis_builder_total_committed_purchase
#: model:ir.model.fields,field_description:mis_builder_total_committed_purchase.field_mis_total_committed_purchase__product_id
msgid "Product"
msgstr "Prodotto"

#. module: mis_builder_total_committed_purchase
#: model:ir.model.fields,field_description:mis_builder_total_committed_purchase.field_mis_total_committed_purchase__purchase_order_id
msgid "Purchase Order"
msgstr "Ordine di acquisto"
Loading