Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NEW] purchase_procurement_analytic: New module
- Loading branch information
1 parent
ccc12ec
commit f8af02e
Showing
10 changed files
with
216 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 Procurement analytic | ||
============================= | ||
|
||
This module takes account analytic value from procurements to the created | ||
purchase order line. | ||
|
||
Configuration | ||
============= | ||
|
||
To configure this module, you need to: | ||
|
||
#. Go to *Settings > Configuration > Accounting > Analytic Accounting*. | ||
#. Enable *Analytic Accounting for Purchases*. | ||
|
||
Usage | ||
===== | ||
|
||
#. Go to *Warehouse > Schedulers > Procurements* and create new. | ||
#. Set *Analytic Account* in *Extra Information* tab. | ||
#. *Run Procurement* | ||
#. The generated purchase order line will have this analytic account. | ||
|
||
.. 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/8.0 | ||
|
||
Known issues / Roadmap | ||
====================== | ||
|
||
* 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. | ||
|
||
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. | ||
|
||
Credits | ||
======= | ||
|
||
Contributors | ||
------------ | ||
* Carlos Dauden <carlos.dauden@tecnativa.com> | ||
* Pedro M. Baeza <pedro.baeza@tecnativa.com> | ||
|
||
Maintainer | ||
---------- | ||
|
||
.. image:: http://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: http://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 http://odoo-community.org. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
'name': 'Purchase Procurement Analytic', | ||
'summary': 'This module sets analytic account in purchase order line from ' | ||
'procurement analytic account', | ||
'version': '8.0.1.0.0', | ||
'category': 'Analytic', | ||
'license': 'AGPL-3', | ||
'author': "Tecnativa, " | ||
"Odoo Community Association (OCA)", | ||
'website': 'http://www.tecnativa.com', | ||
'depends': ['purchase', 'procurement_analytic'], | ||
'installable': True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import procurement | ||
from . import purchase | ||
from . import stock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from openerp import api, models | ||
|
||
|
||
class ProcurementOrder(models.Model): | ||
_inherit = 'procurement.order' | ||
|
||
@api.model | ||
def _get_po_line_values_from_proc( | ||
self, procurement, partner, company, schedule_date): | ||
res = super(ProcurementOrder, self)._get_po_line_values_from_proc( | ||
procurement, partner, company, schedule_date) | ||
res['account_analytic_id'] = procurement.account_analytic_id.id | ||
return res | ||
|
||
@api.multi | ||
def make_po(self): | ||
# This is a trick to avoid the grouping without this key. | ||
obj = self.with_context( | ||
account_analytic_id=self.account_analytic_id.id) | ||
return super(ProcurementOrder, obj).make_po() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from openerp import models | ||
|
||
|
||
class PurchaseOrderLine(models.Model): | ||
_inherit = 'purchase.order.line' | ||
|
||
def search(self, cr, uid, args, offset=0, limit=None, order=None, | ||
context=None, count=False): | ||
if 'account_analytic_id' in context and ( | ||
{'order_id', 'product_id', 'product_uom'} <= | ||
set(x[0] for x in args)): | ||
args.insert(0, ( | ||
'account_analytic_id', '=', context['account_analytic_id'])) | ||
return super(PurchaseOrderLine, self).search( | ||
cr, uid, args, offset=offset, limit=limit, order=order, | ||
context=context, count=count) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from openerp import api, models | ||
|
||
|
||
class StockMove(models.Model): | ||
_inherit = 'stock.move' | ||
|
||
@api.model | ||
def _prepare_procurement_from_move(self, move): | ||
res = super(StockMove, self)._prepare_procurement_from_move(move) | ||
res['account_analytic_id'] = move.procurement_id.account_analytic_id.id | ||
return res |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import test_purchase_procurement_analytic |
55 changes: 55 additions & 0 deletions
55
purchase_procurement_analytic/tests/test_purchase_procurement_analytic.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from openerp.tests.common import TransactionCase | ||
|
||
|
||
class TestPurchaseProcurementAnalytic(TransactionCase): | ||
""" Use case : Prepare some data for current test case """ | ||
def setUp(self): | ||
super(TestPurchaseProcurementAnalytic, self).setUp() | ||
|
||
self.product = self.env.ref('product.product_product_8') | ||
self.analytic_account = self.env['account.analytic.account'].create({ | ||
'name': 'Test Analytic Account', | ||
'type': 'contract', | ||
}) | ||
|
||
procur_vals = { | ||
'name': 'Procurement test', | ||
'product_id': self.product.id, | ||
'product_uom': self.product.uom_id.id, | ||
'warehouse_id': self.env.ref('stock.warehouse0').id, | ||
'location_id': self.env.ref('stock.stock_location_stock').id, | ||
'route_ids': [ | ||
(6, 0, [self.env.ref('purchase.route_warehouse0_buy').id])], | ||
'product_qty': 1.0, | ||
} | ||
self.procurement_1 = self.env['procurement.order'].create(procur_vals) | ||
|
||
procur_vals['account_analytic_id'] = self.analytic_account.id | ||
self.procurement_2 = self.env['procurement.order'].create(procur_vals) | ||
|
||
def test_procurement_to_purchase(self): | ||
# Run procurement | ||
self.procurement_1.run() | ||
self.procurement_2.run() | ||
|
||
# Search purchase order line generate by procurement run | ||
pol = self.env['purchase.order.line'].search( | ||
[('account_analytic_id', '=', self.analytic_account.id)]) | ||
self.assertTrue(pol) | ||
|
||
po_lines = pol.order_id.line_ids.filtered( | ||
lambda x: x.product_id == self.product) | ||
self.assertGreater(len(po_lines), 1) | ||
|
||
# Search stock generate by procurement | ||
stock_move = self.env['stock.move'].search( | ||
[('procurement_id', '=', self.procurement_2.id)]) | ||
self.assertTrue(stock_move) | ||
procur_vals = self.env['stock.move']._prepare_procurement_from_move( | ||
stock_move) | ||
self.assertEqual( | ||
procur_vals['account_analytic_id'], self.analytic_account.id) |