Skip to content

Commit

Permalink
[MIG] purchase_procurement_analytic module: migration to 10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cubells committed Jun 30, 2017
1 parent f9a4f22 commit e9d1b92
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 74 deletions.
15 changes: 8 additions & 7 deletions purchase_procurement_analytic/README.rst
Expand Up @@ -14,21 +14,21 @@ Configuration

To configure this module, you need to:

#. Go to *Settings > Configuration > Accounting > Analytic Accounting*.
#. Enable *Analytic Accounting for Purchases*.
#. Go to your user settings.
#. Enable *Analytic Accounting for Purchases* in *Technical Settings*.

Usage
=====

#. Go to *Warehouse > Schedulers > Procurements* and create new.
#. Go to *Inventory > Reports > Procurement Exceptions* and create a new one.
#. Set *Analytic Account* in *Extra Information* tab.
#. *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/8.0
:target: https://runbot.odoo-community.org/runbot/87/10.0

Known issues / Roadmap
======================
Expand All @@ -52,18 +52,19 @@ Contributors
------------
* Carlos Dauden <carlos.dauden@tecnativa.com>
* Pedro M. Baeza <pedro.baeza@tecnativa.com>
* Vicent Cubells <vicent.cubells@tecnativa.com>

Maintainer
----------

.. image:: http://odoo-community.org/logo.png
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://odoo-community.org
: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 http://odoo-community.org.
To contribute to this module, please visit https://odoo-community.org.
2 changes: 1 addition & 1 deletion purchase_procurement_analytic/__init__.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
@@ -1,17 +1,21 @@
# -*- coding: utf-8 -*-
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# Copyright 2017 Vicent Cubells <vicent.cubells@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',
'version': '10.0.1.0.0',
'category': 'Analytic',
'license': 'AGPL-3',
'author': "Tecnativa, "
"Odoo Community Association (OCA)",
'website': 'http://www.tecnativa.com',
'depends': ['purchase', 'procurement_analytic'],
'depends': [
'purchase',
'procurement_analytic',
],
'installable': True,
}
3 changes: 1 addition & 2 deletions purchase_procurement_analytic/models/__init__.py
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# Copyright 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
15 changes: 7 additions & 8 deletions purchase_procurement_analytic/models/procurement.py
@@ -1,24 +1,23 @@
# -*- coding: utf-8 -*-
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import api, models
from odoo 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
def _prepare_purchase_order_line(self, po, supplier):
res = super(ProcurementOrder, self)._prepare_purchase_order_line(
po, supplier)
res['account_analytic_id'] = self.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)
limit_procurement_account_analytic_id=self.account_analytic_id.id)
return super(ProcurementOrder, obj).make_po()
18 changes: 7 additions & 11 deletions purchase_procurement_analytic/models/purchase.py
@@ -1,20 +1,16 @@
# -*- coding: utf-8 -*-
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import models
from odoo 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']))
def search(self, args, offset=0, limit=None, order=None, count=False):
if 'limit_procurement_account_analytic_id' in self.env.context:
args.insert(0, ('account_analytic_id', '=', self.env.context.get(
'limit_procurement_account_analytic_id')))
return super(PurchaseOrderLine, self).search(
cr, uid, args, offset=offset, limit=limit, order=order,
context=context, count=count)
args, offset=offset, limit=limit, order=order, count=count)
15 changes: 0 additions & 15 deletions purchase_procurement_analytic/models/stock.py

This file was deleted.

2 changes: 1 addition & 1 deletion purchase_procurement_analytic/tests/__init__.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# Copyright 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
@@ -1,35 +1,45 @@
# -*- coding: utf-8 -*-
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# Copyright 2017 Vicent Cubells <vicent.cubells@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp.tests.common import TransactionCase
from odoo.tests import common


class TestPurchaseProcurementAnalytic(TransactionCase):
""" Use case : Prepare some data for current test case """
def setUp(self):
super(TestPurchaseProcurementAnalytic, self).setUp()
class TestPurchaseProcurementAnalytic(common.SavepointCase):
"""Use case : Prepare some data for current test case"""

self.product = self.env.ref('product.product_product_8')
self.analytic_account = self.env['account.analytic.account'].create({
@classmethod
def setUpClass(cls):
super(TestPurchaseProcurementAnalytic, cls).setUpClass()

cls.product = cls.env.ref('product.product_product_8')
cls.analytic_account = cls.env['account.analytic.account'].create({
'name': 'Test Analytic Account',
'type': 'contract',
})

cls.buy_rule = cls.env['procurement.rule'].search([
('action', '=', 'buy'),
('warehouse_id', '=', cls.env.ref('stock.warehouse0').id)])
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,
'product_id': cls.product.id,
'product_uom': cls.product.uom_id.id,
'warehouse_id': cls.env.ref('stock.warehouse0').id,
'location_id': cls.env.ref('stock.stock_location_stock').id,
'route_ids': [
(6, 0, [self.env.ref('purchase.route_warehouse0_buy').id])],
(6, 0, [cls.env.ref('purchase.route_warehouse0_buy').id])],
'rule_id': cls.buy_rule.id,
'product_qty': 1.0,
}
self.procurement_1 = self.env['procurement.order'].create(procur_vals)
cls.procurement_1 = cls.env['procurement.order'].with_context(
{'no_reset_password': True, 'mail_create_nosubscribe': True}
).create(procur_vals)

procur_vals['account_analytic_id'] = self.analytic_account.id
self.procurement_2 = self.env['procurement.order'].create(procur_vals)
procur_vals['account_analytic_id'] = cls.analytic_account.id
procur_vals.update({'product_qty': 2})
cls.procurement_2 = cls.env['procurement.order'].with_context(
{'no_reset_password': True, 'mail_create_nosubscribe': True}
).create(procur_vals)

def test_procurement_to_purchase(self):
# Run procurement
Expand All @@ -41,11 +51,3 @@ def test_procurement_to_purchase(self):
self.assertEqual(
self.procurement_2.purchase_line_id.account_analytic_id.id,
self.analytic_account.id)
po = self.procurement_2.purchase_id
# Confirm PO to create stock.move
po.signal_workflow("purchase_confirm")
stock_move = self.procurement_2.purchase_line_id.move_ids[0]
procur_vals = self.env['stock.move']._prepare_procurement_from_move(
stock_move)
self.assertEqual(
procur_vals['account_analytic_id'], self.analytic_account.id)

0 comments on commit e9d1b92

Please sign in to comment.