diff --git a/purchase_request_analytic/README.rst b/purchase_request_analytic/README.rst new file mode 100644 index 0000000000..aad315c6af --- /dev/null +++ b/purchase_request_analytic/README.rst @@ -0,0 +1,104 @@ +========================= +Purchase Request Analytic +========================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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%2Faccount--analytic-lightgray.png?logo=github + :target: https://github.com/OCA/account-analytic/tree/15.0/purchase_request_analytic + :alt: OCA/account-analytic +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-analytic-15-0/account-analytic-15-0-purchase_request_analytic + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/87/15.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds the analytic account field to Purchase Requests. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +* Assign an analytic account to the purchase request or to purchase request lines. + +Changelog +========= + +13.0.1.0.0 (2020-01-08) +~~~~~~~~~~~~~~~~~~~~~~~ + +Migrated to odoo 13. + +12.0.1.0.0 (2019-10-30) +~~~~~~~~~~~~~~~~~~~~~~~ + +Migrated to odoo 12. + +10.0.1.0.1 (2019-05-09) +~~~~~~~~~~~~~~~~~~~~~~~ + +[FIX] Do not restrict picking type for analytic. +[IMP] Add tests. + +10.0.1.0.0 (2019-04-29) +~~~~~~~~~~~~~~~~~~~~~~~ + +First version. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ForgeFlow + +Contributors +~~~~~~~~~~~~ + +* Beñat Jimenez +* Pimolnat Suntian +* Juany Davila + +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/account-analytic `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/purchase_request_analytic/__init__.py b/purchase_request_analytic/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/purchase_request_analytic/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/purchase_request_analytic/__manifest__.py b/purchase_request_analytic/__manifest__.py new file mode 100644 index 0000000000..5b2fff35a9 --- /dev/null +++ b/purchase_request_analytic/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2019 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Purchase Request Analytic", + "version": "15.0.1.0.0", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "category": "Purchase Management", + "website": "https://github.com/OCA/account-analytic", + "depends": ["purchase_request"], + "data": ["views/purchase_request_views.xml"], + "license": "AGPL-3", + "installable": True, +} diff --git a/purchase_request_analytic/i18n/purchase_request_analytic.pot b/purchase_request_analytic/i18n/purchase_request_analytic.pot new file mode 100644 index 0000000000..62bc5c45f9 --- /dev/null +++ b/purchase_request_analytic/i18n/purchase_request_analytic.pot @@ -0,0 +1,55 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_request_analytic +# +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: purchase_request_analytic +#: model:ir.model.fields,field_description:purchase_request_analytic.field_purchase_request__analytic_account_id +#: model_terms:ir.ui.view,arch_db:purchase_request_analytic.view_purchase_request_search +msgid "Analytic Account" +msgstr "" + +#. module: purchase_request_analytic +#: model:ir.model.fields,field_description:purchase_request_analytic.field_purchase_request__analytic_account_id2 +msgid "Analytic Account Id2" +msgstr "" + +#. module: purchase_request_analytic +#: model:ir.model.fields,field_description:purchase_request_analytic.field_purchase_request__display_name +msgid "Display Name" +msgstr "" + +#. module: purchase_request_analytic +#: model:ir.model.fields,field_description:purchase_request_analytic.field_purchase_request__id +msgid "ID" +msgstr "" + +#. module: purchase_request_analytic +#: model:ir.model.fields,field_description:purchase_request_analytic.field_purchase_request____last_update +msgid "Last Modified on" +msgstr "" + +#. module: purchase_request_analytic +#: model:ir.model,name:purchase_request_analytic.model_purchase_request +msgid "Purchase Request" +msgstr "" + +#. module: purchase_request_analytic +#: model:ir.model.fields,help:purchase_request_analytic.field_purchase_request__analytic_account_id +msgid "The analytic account related to a sales order." +msgstr "" + +#. module: purchase_request_analytic +#: model:ir.model.fields,help:purchase_request_analytic.field_purchase_request__analytic_account_id2 +msgid "Use to store the value of analytic_account if there is no lines" +msgstr "" diff --git a/purchase_request_analytic/models/__init__.py b/purchase_request_analytic/models/__init__.py new file mode 100644 index 0000000000..91be581c56 --- /dev/null +++ b/purchase_request_analytic/models/__init__.py @@ -0,0 +1 @@ +from . import purchase_request diff --git a/purchase_request_analytic/models/purchase_request.py b/purchase_request_analytic/models/purchase_request.py new file mode 100644 index 0000000000..494f619cb7 --- /dev/null +++ b/purchase_request_analytic/models/purchase_request.py @@ -0,0 +1,42 @@ +# Copyright 2019 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class PurchaseRequest(models.Model): + _inherit = "purchase.request" + + analytic_account_id = fields.Many2one( + compute="_compute_analytic_account_id", + inverse="_inverse_analytic_account_id", + comodel_name="account.analytic.account", + string="Analytic Account", + readonly=True, + states={"draft": [("readonly", False)]}, + store=True, + help="The analytic account related to a sales order.", + ) + + @api.depends("line_ids.analytic_account_id") + def _compute_analytic_account_id(self): + """If all purchase request lines have same analytic account set + analytic_account_id + """ + for pr in self: + al = pr.analytic_account_id + if pr.line_ids: + for prl in pr.line_ids: + if prl.analytic_account_id != al: + al = False + break + pr.analytic_account_id = al + + def _inverse_analytic_account_id(self): + """If analytic_account is set on PR, propagate it to all purchase + request lines + """ + for pr in self: + if pr.analytic_account_id: + for line in pr.line_ids: + line.analytic_account_id = pr.analytic_account_id.id diff --git a/purchase_request_analytic/readme/CONTRIBUTORS.rst b/purchase_request_analytic/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..a7df2a8929 --- /dev/null +++ b/purchase_request_analytic/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* Beñat Jimenez +* Pimolnat Suntian +* Juany Davila diff --git a/purchase_request_analytic/readme/DESCRIPTION.rst b/purchase_request_analytic/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..7910de960d --- /dev/null +++ b/purchase_request_analytic/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module adds the analytic account field to Purchase Requests. diff --git a/purchase_request_analytic/readme/HISTORY.rst b/purchase_request_analytic/readme/HISTORY.rst new file mode 100644 index 0000000000..abc36de86d --- /dev/null +++ b/purchase_request_analytic/readme/HISTORY.rst @@ -0,0 +1,20 @@ +13.0.1.0.0 (2020-01-08) +~~~~~~~~~~~~~~~~~~~~~~~ + +Migrated to odoo 13. + +12.0.1.0.0 (2019-10-30) +~~~~~~~~~~~~~~~~~~~~~~~ + +Migrated to odoo 12. + +10.0.1.0.1 (2019-05-09) +~~~~~~~~~~~~~~~~~~~~~~~ + +[FIX] Do not restrict picking type for analytic. +[IMP] Add tests. + +10.0.1.0.0 (2019-04-29) +~~~~~~~~~~~~~~~~~~~~~~~ + +First version. diff --git a/purchase_request_analytic/readme/USAGE.rst b/purchase_request_analytic/readme/USAGE.rst new file mode 100644 index 0000000000..d90de9636c --- /dev/null +++ b/purchase_request_analytic/readme/USAGE.rst @@ -0,0 +1 @@ +* Assign an analytic account to the purchase request or to purchase request lines. diff --git a/purchase_request_analytic/static/description/icon.png b/purchase_request_analytic/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/purchase_request_analytic/static/description/icon.png differ diff --git a/purchase_request_analytic/static/description/index.html b/purchase_request_analytic/static/description/index.html new file mode 100644 index 0000000000..1ffd72048c --- /dev/null +++ b/purchase_request_analytic/static/description/index.html @@ -0,0 +1,455 @@ + + + + + + +Purchase Request Analytic + + + +
+

Purchase Request Analytic

+ + +

Beta License: AGPL-3 OCA/account-analytic Translate me on Weblate Try me on Runbot

+

This module adds the analytic account field to Purchase Requests.

+

Table of contents

+ +
+

Usage

+
    +
  • Assign an analytic account to the purchase request or to purchase request lines.
  • +
+
+
+

Changelog

+
+

13.0.1.0.0 (2020-01-08)

+

Migrated to odoo 13.

+
+
+

12.0.1.0.0 (2019-10-30)

+

Migrated to odoo 12.

+
+
+

10.0.1.0.1 (2019-05-09)

+

[FIX] Do not restrict picking type for analytic. +[IMP] Add tests.

+
+
+

10.0.1.0.0 (2019-04-29)

+

First version.

+
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • ForgeFlow
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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/account-analytic project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/purchase_request_analytic/tests/__init__.py b/purchase_request_analytic/tests/__init__.py new file mode 100644 index 0000000000..278e1dc2f6 --- /dev/null +++ b/purchase_request_analytic/tests/__init__.py @@ -0,0 +1 @@ +from . import test_purchase_request_analytic diff --git a/purchase_request_analytic/tests/test_purchase_request_analytic.py b/purchase_request_analytic/tests/test_purchase_request_analytic.py new file mode 100644 index 0000000000..1c51b398c1 --- /dev/null +++ b/purchase_request_analytic/tests/test_purchase_request_analytic.py @@ -0,0 +1,50 @@ +# Copyright 2019 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.tests.common import TransactionCase + + +class TestPurchaseRequestAnalytic(TransactionCase): + def setUp(self): + super(TestPurchaseRequestAnalytic, self).setUp() + self.anal_id = self.env["account.analytic.account"].create( + {"name": "Account Analytic for Tests"} + ) + + def test_analytic_account(self): + """Create a purchase order with line + Set analytic account on purchase + Check analytic account on line is set + """ + product_id = self.env.ref("product.product_product_9") + pr = self.env["purchase.request"].create( + { + "requested_by": self.env.user.id, + "line_ids": [ + ( + 0, + 0, + { + "name": product_id.name, + "product_id": product_id.id, + "product_qty": 1.0, + "product_uom_id": self.env.ref("uom.product_uom_unit").id, + }, + ) + ], + } + ) + + pr.analytic_account_id = self.anal_id.id + self.assertEqual(pr.analytic_account_id.id, self.anal_id.id) + self.assertEqual(pr.line_ids.analytic_account_id.id, self.anal_id.id) + + def test_analytic(self): + """Create a purchase order without line + Set analytic account on purchase + Check analytic account is on purchase + """ + pr = self.env["purchase.request"].new( + {"requested_by": self.env.user.id, "analytic_account_id": self.anal_id.id} + ) + self.assertEqual(pr.analytic_account_id.id, self.anal_id.id) diff --git a/purchase_request_analytic/views/purchase_request_views.xml b/purchase_request_analytic/views/purchase_request_views.xml new file mode 100644 index 0000000000..1deafa7164 --- /dev/null +++ b/purchase_request_analytic/views/purchase_request_views.xml @@ -0,0 +1,55 @@ + + + + purchase.request.analytic.tree + purchase.request + + + + + + + + + purchase.request.analytic.form + purchase.request + + + + + + + + {'default_analytic_account_id': analytic_account_id} + + + + + + purchase.request.search + purchase.request + + + + + + + + + + + diff --git a/setup/purchase_request_analytic/odoo/addons/purchase_request_analytic b/setup/purchase_request_analytic/odoo/addons/purchase_request_analytic new file mode 120000 index 0000000000..c889458d7c --- /dev/null +++ b/setup/purchase_request_analytic/odoo/addons/purchase_request_analytic @@ -0,0 +1 @@ +../../../../purchase_request_analytic \ No newline at end of file diff --git a/setup/purchase_request_analytic/setup.py b/setup/purchase_request_analytic/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/purchase_request_analytic/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)