Skip to content

Commit

Permalink
[IMP] purchase_procurement_analytic: Allow to select a strategy for g…
Browse files Browse the repository at this point in the history
…rouping

As to keep former process and give also the ability to group per line,
an option is added in configuration that allows user to choose either
to group purchase order lines together on the same analytic account or
to group purchase orders per analytic account.
  • Loading branch information
rousseldenis committed Jul 5, 2022
1 parent 95af2d2 commit 12bd16c
Show file tree
Hide file tree
Showing 18 changed files with 738 additions and 149 deletions.
100 changes: 68 additions & 32 deletions purchase_procurement_analytic/README.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

=============================
Purchase Procurement analytic
Purchase Procurement Analytic
=============================

This module takes account analytic value from procurements to the created
purchase order line.
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! 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/14.0/purchase_procurement_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-14-0/account-analytic-14-0-purchase_procurement_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/14.0
:alt: Try me on Runbot

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

This module allows either:

* To group generated purchase order lines per analytic account
* To group generated purchase orders per analytic account

**Table of contents**

.. contents::
:local:

Configuration
=============
Expand All @@ -20,52 +46,62 @@ To configure this module, you need to:
Usage
=====

#. Go to *Inventory > Reports > Procurement Exceptions* and create a new one.
#. Set *Analytic Account*.
#. *Run Procurement*
#. The generated purchase order line will have this analytic account.
They won't be grouped if analytic account is different.

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/87/10.0

Known issues / Roadmap
======================
You need to configure the way purchase generation will behave.

* If product supplier info min quantity is greater than procurement qty and we
have sale orders with distinct analytic account which contains this product,
each purchase order line takes seller min quantity.
* Go to Purchase > Configuration
* Select either purchase grouping per anlaytic:
* Per order (default)
* Per line


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

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/account-analytic/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.
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-analytic/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/account-analytic/issues/new?body=module:%20purchase_procurement_analytic%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
~~~~~~~

* ACSONE SA/NV
* Tecnativa

Contributors
------------
~~~~~~~~~~~~

* Carlos Dauden <[email protected]>
* Pedro M. Baeza <[email protected]>
* Vicent Cubells <[email protected]>
* Denis Roussel <[email protected]>

Maintainer
----------
Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

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

This module is maintained by the OCA.

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.

To contribute to this module, please visit https://odoo-community.org.
.. |maintainer-rousseldenis| image:: https://github.com/rousseldenis.png?size=40px
:target: https://github.com/rousseldenis
:alt: rousseldenis

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

|maintainer-rousseldenis|

This module is part of the `OCA/account-analytic <https://github.com/OCA/account-analytic/tree/14.0/purchase_procurement_analytic>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions purchase_procurement_analytic/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"purchase_stock",
"stock_analytic",
],
"data": ["views/res_config_settings.xml"],
"installable": True,
}
3 changes: 3 additions & 0 deletions purchase_procurement_analytic/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
from . import stock_rule
from . import purchase_order_line
from . import res_company
from . import res_config_settings
6 changes: 6 additions & 0 deletions purchase_procurement_analytic/models/purchase_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def _find_candidate(
company_id,
values,
)
if company_id.purchase_analytic_grouping != "line":
return line
analytic_id = values.get("analytic_account_id")
if analytic_id:
line_candidates = self.filtered(
Expand All @@ -48,6 +50,10 @@ def _find_candidate(
def _prepare_purchase_order_line_from_procurement(
self, product_id, product_qty, product_uom, company_id, values, po
):
"""
Add analytic account to purchase order line if analytic account
comes from procurement.
"""
res = super()._prepare_purchase_order_line_from_procurement(
product_id, product_qty, product_uom, company_id, values, po
)
Expand Down
15 changes: 15 additions & 0 deletions purchase_procurement_analytic/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2022 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResCompany(models.Model):

_inherit = "res.company"

purchase_analytic_grouping = fields.Selection(
[("order", "Per Order"), ("line", "Per line")],
default="order",
required=True,
)
15 changes: 15 additions & 0 deletions purchase_procurement_analytic/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2022 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResConfigSettings(models.TransientModel):

_inherit = "res.config.settings"

purchase_analytic_grouping = fields.Selection(
related="company_id.purchase_analytic_grouping",
readonly=False,
required=True,
)
22 changes: 22 additions & 0 deletions purchase_procurement_analytic/models/stock_rule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2022 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models


class StockRule(models.Model):

_inherit = "stock.rule"

def _make_po_get_domain(self, company_id, values, partner):
"""
If the grouping strategy is set 'per order' and if an analytic
account is set on procurement, add the analytic account in the
criteria to find an eligible purchase order.
"""
domain = super()._make_po_get_domain(company_id, values, partner)
if company_id.purchase_analytic_grouping == "order":
analytic_id = values.get("analytic_account_id")
if analytic_id:
domain += (("order_line.account_analytic_id", "=", analytic_id),)
return domain
4 changes: 4 additions & 0 deletions purchase_procurement_analytic/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
To configure this module, you need to:

#. Go to your user settings.
#. Enable *Analytic Accounting for Purchases* in *Technical Settings*.
3 changes: 3 additions & 0 deletions purchase_procurement_analytic/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
* Carlos Dauden <[email protected]>
* Pedro M. Baeza <[email protected]>
* Vicent Cubells <[email protected]>
* Denis Roussel <[email protected]>
6 changes: 4 additions & 2 deletions purchase_procurement_analytic/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
This module allows to not group purchase lines that concern different
analytic account if created from procurements.
This module allows either:

* To group generated purchase order lines per analytic account
* To group generated purchase orders per analytic account
6 changes: 6 additions & 0 deletions purchase_procurement_analytic/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
You need to configure the way purchase generation will behave.

* Go to Purchase > Configuration
* Select either purchase grouping per analytic:
* Per order (default)
* Per line
Loading

0 comments on commit 12bd16c

Please sign in to comment.