Skip to content

Commit

Permalink
Merge PR #410 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by AaronHForgeFlow
  • Loading branch information
OCA-git-bot committed Feb 8, 2022
2 parents 72abd3c + 154aa69 commit 8e751de
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 0 deletions.
62 changes: 62 additions & 0 deletions purchase_stock_analytic/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
.. 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 Stock Analytic
=======================

Copies the analytic account of the purchase order item to the stock move

Usage
=====

To use this module, you need to:

#. Create a purchase order
#. Set an analytic account and analytic tags on purchase order lines
#. Confirm purchase order
#. ... and you should have your analytic account and analytic tags on your stock moves

.. 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/13.0

.. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt
.. branch is "8.0" for example
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 smash it by providing detailed and welcomed feedback.

Credits
=======

Images
------

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

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

* Benoit Aimont <[email protected]>

Maintainer
----------

.. 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.
1 change: 1 addition & 0 deletions purchase_stock_analytic/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
13 changes: 13 additions & 0 deletions purchase_stock_analytic/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2020 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Purchase Stock Analytic",
"summary": """
Copies the analytic account of the purchase order item to the stock move""",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-analytic",
"depends": ["purchase_stock", "stock_analytic"],
}
1 change: 1 addition & 0 deletions purchase_stock_analytic/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import purchase_order_line
20 changes: 20 additions & 0 deletions purchase_stock_analytic/models/purchase_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2020 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class PurchaseOrderLine(models.Model):

_inherit = "purchase.order.line"

def _prepare_stock_moves(self, picking):
res = super(PurchaseOrderLine, self)._prepare_stock_moves(picking)
for line in res:
account_analytic = self.account_analytic_id
analytic_tags = self.analytic_tag_ids
if account_analytic:
line.update({"analytic_account_id": account_analytic.id})
if analytic_tags:
line.update({"analytic_tag_ids": [(6, 0, analytic_tags.ids)]})
return res
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions purchase_stock_analytic/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_purchase_stock_analytic
51 changes: 51 additions & 0 deletions purchase_stock_analytic/tests/test_purchase_stock_analytic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2020 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields
from odoo.tests.common import SavepointCase


class TestPurchaseStockAnalytic(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.purchase_order_model = cls.env["purchase.order"]
cls.purchase_order_line_model = cls.env["purchase.order.line"]
cls.analytic_tag_model = cls.env["account.analytic.tag"]
cls.product_model = cls.env["product.product"]
cls.res_partner_model = cls.env["res.partner"]

cls.analytic_tag_1 = cls.analytic_tag_model.create({"name": "Tag test 1"})
cls.analytic_tag_2 = cls.analytic_tag_model.create({"name": "Tag test 2"})
cls.partner = cls.res_partner_model.create({"name": "Partner test"})
cls.product = cls.product_model.create({"name": "Product test"})
cls.analytic_account = cls.env.ref("analytic.analytic_agrolait")

cls.purchase_order = cls.purchase_order_model.create(
{"partner_id": cls.partner.id}
)
cls.purchase_order_line = cls.purchase_order_line_model.create(
{
"name": "purchase order line test",
"product_qty": 3,
"order_id": cls.purchase_order.id,
"price_unit": 20,
"product_id": cls.product.id,
"account_analytic_id": cls.analytic_account.id,
"analytic_tag_ids": [
(6, 0, [cls.analytic_tag_1.id, cls.analytic_tag_2.id])
],
"date_planned": fields.Datetime.today(),
"product_uom": cls.product.uom_po_id.id,
}
)

def test_purchase_stock_analytic(self):
self.purchase_order.button_confirm()
self.move = self.purchase_order.picking_ids.move_ids_without_package
self.assertEqual(self.move.analytic_account_id, self.analytic_account)
self.assertEqual(
self.move.analytic_tag_ids.ids,
[self.analytic_tag_1.id, self.analytic_tag_2.id],
)
6 changes: 6 additions & 0 deletions setup/purchase_stock_analytic/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 8e751de

Please sign in to comment.