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

[14.0][MIG] product_analytic_purchase: Migration to 14.0 #376

Merged
merged 9 commits into from
May 17, 2022
59 changes: 59 additions & 0 deletions product_analytic_purchase/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
.. 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

=========================
Product Analytic Purchase
=========================

This module is a glue module between the *product_analytic* and
*purchase* modules.

Usage
=====

When you create a purchase order line with a product that has an
**expense analytic account** (or whose internal category has an
**expense analytic account**), it will be automatically set on the
purchase order line.

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

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

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/analytic-account/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
------------

* Alexis de Lattre <[email protected]>
Reyes4711-S73 marked this conversation as resolved.
Show resolved Hide resolved
* Carlos Reyes <[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 product_analytic_purchase/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
15 changes: 15 additions & 0 deletions product_analytic_purchase/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2017 Akretion (http://www.akretion.com/) - Alexis de Lattre
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Product Analytic Purchase",
"version": "14.0.1.0.0",
"category": "Purchases",
"license": "AGPL-3",
"summary": "Glue module between purchase and product_analytic",
"author": "Akretion, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-analytic",
"depends": ["purchase", "product_analytic"],
"auto_install": True,
"installable": True,
}
22 changes: 22 additions & 0 deletions product_analytic_purchase/i18n/ca.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * product_analytic_purchase
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2018-10-12 20:00+0000\n"
"Last-Translator: Harald Panten <[email protected]>\n"
"Language-Team: none\n"
"Language: ca\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 3.1.1\n"

#. module: product_analytic_purchase
#: model:ir.model,name:product_analytic_purchase.model_purchase_order_line
msgid "Purchase Order Line"
msgstr "Línia de comanda de compra"
25 changes: 25 additions & 0 deletions product_analytic_purchase/i18n/cs_CZ.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * product_analytic_purchase
#
# Translators:
# Lukáš Spurný <[email protected]>, 2018
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-02-21 03:54+0000\n"
"PO-Revision-Date: 2018-02-21 03:54+0000\n"
"Last-Translator: Lukáš Spurný <[email protected]>, 2018\n"
"Language-Team: Czech (Czech Republic) (https://www.transifex.com/oca/"
"teams/23907/cs_CZ/)\n"
"Language: cs_CZ\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n"

#. module: product_analytic_purchase
#: model:ir.model,name:product_analytic_purchase.model_purchase_order_line
msgid "Purchase Order Line"
msgstr "Řádek objednávky"
24 changes: 24 additions & 0 deletions product_analytic_purchase/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * product_analytic_purchase
#
# Translators:
# enjolras <[email protected]>, 2018
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-02-21 03:54+0000\n"
"PO-Revision-Date: 2018-02-21 03:54+0000\n"
"Last-Translator: enjolras <[email protected]>, 2018\n"
"Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n"
"Language: es\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"

#. module: product_analytic_purchase
#: model:ir.model,name:product_analytic_purchase.model_purchase_order_line
msgid "Purchase Order Line"
msgstr "Línea de pedido de compra"
24 changes: 24 additions & 0 deletions product_analytic_purchase/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * product_analytic_purchase
#
# Translators:
# Quentin THEURET <[email protected]>, 2018
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-02-23 23:11+0000\n"
"PO-Revision-Date: 2018-02-23 23:11+0000\n"
"Last-Translator: Quentin THEURET <[email protected]>, 2018\n"
"Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n"
"Language: fr\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"

#. module: product_analytic_purchase
#: model:ir.model,name:product_analytic_purchase.model_purchase_order_line
msgid "Purchase Order Line"
msgstr "Ligne de commande"
25 changes: 25 additions & 0 deletions product_analytic_purchase/i18n/hr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * product_analytic_purchase
#
# Translators:
# Bole <[email protected]>, 2018
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-02-21 03:54+0000\n"
"PO-Revision-Date: 2018-02-21 03:54+0000\n"
"Last-Translator: Bole <[email protected]>, 2018\n"
"Language-Team: Croatian (https://www.transifex.com/oca/teams/23907/hr/)\n"
"Language: hr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"

#. module: product_analytic_purchase
#: model:ir.model,name:product_analytic_purchase.model_purchase_order_line
msgid "Purchase Order Line"
msgstr "Stavka naloga za nabavu"
20 changes: 20 additions & 0 deletions product_analytic_purchase/i18n/product_analytic_purchase.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * product_analytic_purchase
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.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: product_analytic_purchase
#: model:ir.model,name:product_analytic_purchase.model_purchase_order_line
msgid "Purchase Order Line"
msgstr ""

1 change: 1 addition & 0 deletions product_analytic_purchase/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import purchase_order_line
28 changes: 28 additions & 0 deletions product_analytic_purchase/models/purchase_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2017 Akretion (http://www.akretion.com/) - Alexis de Lattre
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, models


class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"

@api.onchange("product_id")
def onchange_product_id(self):
res = super(PurchaseOrderLine, self).onchange_product_id()
if self.product_id:
ana_accounts = (
self.product_id.product_tmpl_id._get_product_analytic_accounts()
)
ana_account = ana_accounts["expense"]
self.account_analytic_id = ana_account.id
return res

@api.model
def create(self, vals):
if vals.get("product_id") and not vals.get("account_analytic_id"):
product = self.env["product.product"].browse(vals.get("product_id"))
ana_accounts = product.product_tmpl_id._get_product_analytic_accounts()
ana_account = ana_accounts["expense"]
vals["account_analytic_id"] = ana_account.id
return super(PurchaseOrderLine, self).create(vals)
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 product_analytic_purchase/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_purchase
88 changes: 88 additions & 0 deletions product_analytic_purchase/tests/test_purchase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# © 2015 Antiun Ingenieria - Javier Iniesta
# © 2017 Tecnativa - Luis Martínez
# © 2017 Akretion (Alexis de Lattre <[email protected]>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.tests.common import TransactionCase


class TestPurchaseOrderLine(TransactionCase):
def setUp(self):
super(TestPurchaseOrderLine, self).setUp()
self.analytic = self.env["account.analytic.account"].create(
{
"name": "Our Super Product Development",
}
)
self.product1 = self.env["product.product"].create(
{
"name": "Computer SC234",
"categ_id": self.env.ref("product.product_category_all").id,
"list_price": 450.0,
"standard_price": 300.0,
"type": "consu",
"uom_id": self.env.ref("uom.product_uom_unit").id,
"uom_po_id": self.env.ref("uom.product_uom_unit").id,
"description_sale": "17 LCD Monitor Processor AMD",
}
)
self.product2 = self.env["product.product"].create(
{
"name": "Prepaid Consulting",
"categ_id": self.env.ref("product.product_category_all").id,
"list_price": 90,
"standard_price": 40,
"type": "service",
"uom_id": self.env.ref("uom.product_uom_hour").id,
"uom_po_id": self.env.ref("uom.product_uom_hour").id,
"description": "Example of product to invoice on order.",
"default_code": "SERV_ORDER",
"expense_analytic_account_id": self.analytic.id,
"income_analytic_account_id": self.analytic.id,
}
)
self.assertTrue(self.product2.expense_analytic_account_id)
self.po = self.env["purchase.order"].create(
{
"partner_id": self.env.ref("base.res_partner_1").id,
"order_line": [
(
0,
0,
{
"product_id": self.product1.id,
"name": self.product1.name,
"date_planned": "2017-07-17 12:42:12",
"product_qty": 12,
"product_uom": self.product1.uom_id.id,
"price_unit": 42,
},
)
],
}
)
self.po_line1 = self.po.order_line[0]

def test_onchange_product_id(self):
self.po_line1.product_id = self.product2.id
self.po_line1.onchange_product_id()
self.assertEqual(
self.po_line1.account_analytic_id.id,
self.product2.expense_analytic_account_id.id,
)

def test_create(self):
pol_vals = {
"product_id": self.product2.id,
"name": self.product2.name,
"date_planned": "2017-07-17 12:42:12",
"product_qty": 42,
"product_uom": self.product2.uom_id.id,
"price_unit": 42,
"order_id": self.po.id,
}
po_line2 = self.env["purchase.order.line"].create(pol_vals)
self.assertEqual(
po_line2.account_analytic_id.id,
self.product2.expense_analytic_account_id.id,
)
6 changes: 6 additions & 0 deletions setup/product_analytic_purchase/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,
)