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

my improvements on the migration of purchase_order_analytic_search #21

Open
wants to merge 5 commits into
base: 10.0-mig-purchase_order_analytic_search
Choose a base branch
from
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
62 changes: 36 additions & 26 deletions purchase_discount/tests/test_purchase_discount.py
Original file line number Diff line number Diff line change
@@ -1,64 +1,68 @@
# -*- coding: utf-8 -*-
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
# Copyright 2015-2017 Tecnativa - Pedro M. Baeza
# Copyright 2015-2018 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import odoo.tests.common as common
from odoo import fields


class TestPurchaseOrder(common.SavepointCase):
@classmethod
def setUpClass(cls):
super(TestPurchaseOrder, cls).setUpClass()
cls.product_1 = cls.env['product.product'].create({
class TestPurchaseOrder(common.HttpCase):
at_install = False
post_install = False

def setUp(self):
super(TestPurchaseOrder, self).setUp()
self.company = self.env.user.company_id
self.company.tax_calculation_rounding_method = 'round_per_line'
self.product_1 = self.env['product.product'].create({
'name': 'Test product 1',
})
cls.product_2 = cls.env['product.product'].create({
self.product_2 = self.env['product.product'].create({
'name': 'Test product 2',
})
po_model = cls.env['purchase.order.line']
po_model = self.env['purchase.order.line']
# Make sure currency is EUR for not having troubles with rates
cls.env.user.company_id.currency_id = cls.env.ref('base.EUR')
cls.purchase_order = cls.env['purchase.order'].create({
'partner_id': cls.env.ref('base.res_partner_3').id,
self.env.user.company_id.currency_id = self.env.ref('base.EUR')
self.purchase_order = self.env['purchase.order'].create({
'partner_id': self.env.ref('base.res_partner_3').id,
})
cls.po_line_1 = po_model.create({
'order_id': cls.purchase_order.id,
'product_id': cls.product_1.id,
self.po_line_1 = po_model.create({
'order_id': self.purchase_order.id,
'product_id': self.product_1.id,
'date_planned': fields.Datetime.now(),
'name': 'Test',
'product_qty': 1.0,
'product_uom': cls.product_1.uom_id.id,
'product_uom': self.product_1.uom_id.id,
'discount': 50.0,
'price_unit': 10.0,
})
cls.tax = cls.env['account.tax'].create({
self.tax = self.env['account.tax'].create({
'name': 'Sample tax 15%',
'amount_type': 'percent',
'type_tax_use': 'purchase',
'amount': 15.0,
})
cls.po_line_2 = po_model.create({
'order_id': cls.purchase_order.id,
'product_id': cls.product_2.id,
self.po_line_2 = po_model.create({
'order_id': self.purchase_order.id,
'product_id': self.product_2.id,
'date_planned': fields.Datetime.now(),
'name': 'Test',
'product_qty': 10.0,
'product_uom': cls.product_2.uom_id.id,
'product_uom': self.product_2.uom_id.id,
'discount': 30,
'taxes_id': [(6, 0, [cls.tax.id])],
'taxes_id': [(6, 0, [self.tax.id])],
'price_unit': 230.0,
})
cls.po_line_3 = po_model.create({
'order_id': cls.purchase_order.id,
'product_id': cls.product_2.id,
self.po_line_3 = po_model.create({
'order_id': self.purchase_order.id,
'product_id': self.product_2.id,
'date_planned': fields.Datetime.now(),
'name': 'Test',
'product_qty': 1.0,
'product_uom': cls.product_2.uom_id.id,
'product_uom': self.product_2.uom_id.id,
'discount': 0,
'taxes_id': [(6, 0, [cls.tax.id])],
'taxes_id': [(6, 0, [self.tax.id])],
'price_unit': 10.0,
})

Expand All @@ -82,3 +86,9 @@ def test_report_price_unit(self):
])
self.assertEqual(rec.price_total, 5)
self.assertEqual(rec.discount, 50)


class TestPurchaseOrderRoundGlobally(TestPurchaseOrder):
def setUp(self):
super(TestPurchaseOrderRoundGlobally, self).setUp()
self.company.tax_calculation_rounding_method = 'round_globally'
68 changes: 68 additions & 0 deletions purchase_order_analytic_search/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
.. 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 Order Analytic Search
==============================

Organizations often require to quickly find the purchase orders associated to
an analytic account, searching by it's code, name or project/account manager.

This module introduces the possibility to search purchase orders by analytic
account.

It also introduces a new menu entry in Purchasing to list purchase order lines.


Usage
=====

To use this module, you need to:

#. Set 'Analytic Accounting' and 'Analytic Accounting for
Purchases' user rights.


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


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

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

* Gisela Mora <gisela.mora@eficent.com>
* Serpent Consulting Services Pvt. Ltd. <support@serpentcs.com>
* Alexandre Fayolle <alexandre.fayolle@camptocamp.com>

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.
5 changes: 5 additions & 0 deletions purchase_order_analytic_search/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2015-17 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from . import models
22 changes: 22 additions & 0 deletions purchase_order_analytic_search/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Copyright 2015-17 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

{
"name": "Purchase Order Analytic Search",
"summary": """Search purchase orders by analytic account. New menu entry in
Purchasing to list purchase order lines.""",
"version": "10.0.1.0.0",
"website": "https://odoo-community.org/",
"category": "Purchase Workflow",
"author": "Eficent, Camptocamp, Odoo Community Association (OCA)",
"license": "LGPL-3",
"installable": True,
"depends": [
"analytic",
"purchase"
],
"data": [
"views/purchase_order_view.xml"
],
}
5 changes: 5 additions & 0 deletions purchase_order_analytic_search/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2015-17 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from . import purchase_order
53 changes: 53 additions & 0 deletions purchase_order_analytic_search/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Eficent Business and IT Consulting Services S.L.
# Copyright 2018 Camptocamp
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from odoo import api, fields, models


class PurchaseOrder(models.Model):

_inherit = "purchase.order"

@api.multi
@api.depends('order_line.account_analytic_id')
def _compute_analytic_accounts(self):
for purchase in self:
purchase.account_analytic_ids = purchase.mapped(
'order_line.account_analytic_id'
)

@api.model
def _search_analytic_accounts(self, operator, value):
po_line_obj = self.env['purchase.order.line']
if not value:
return [('id', '=', False)]
if isinstance(value, (tuple, list)):
# we are searching on a list of ids
domain = [('order_id', '!=', False),
('account_analytic_id', 'in', value)]
else:
if isinstance(value, int):
# we are searching on the id of the analytic_account
domain = [('order_id', '!=', False),
('account_analytic_id', '=', value)]
else:
# assume we are searching on the analytic account name
domain = [('order_id', '!=', False),
('account_analytic_id.name', 'like', value),
]
po_lines = po_line_obj.search(domain)
orders = po_lines.mapped('order_id')
if operator in ('!=', 'not in'):
return [('id', 'not in', orders.ids)]
else:
return [('id', 'in', orders.ids)]

account_analytic_ids = fields.Many2many(
comodel_name='account.analytic.account',
string='Analytic Account',
compute='_compute_analytic_accounts',
search='_search_analytic_accounts',
readonly=True
)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions purchase_order_analytic_search/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2015-17 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from . import test_analytic_search
Loading