[10.0][MIG] procurement_auto_create_group

This commit is contained in:
lreficent
2018-01-11 12:27:15 +01:00
committed by Laurent Mignon (ACSONE)
parent 670d26a116
commit 24694947e7
7 changed files with 33 additions and 19 deletions

View File

@@ -38,7 +38,7 @@ Usage
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/153/9.0
:target: https://runbot.odoo-community.org/runbot/153/10.0
Bug Tracker
===========

View File

@@ -1,5 +1,4 @@
# # -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models

View File

@@ -3,7 +3,10 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Procurement Auto Create Group",
"version": "9.0.1.0.0",
"version": "10.0.1.0.0",
"license": "AGPL-3",
"summary": "Allows to configure the system to propose automatically new "
"procurement groups in procurement orders.",
"depends": [
"procurement",
],
@@ -15,5 +18,4 @@
'views/procurement_view.xml',
],
"installable": True,
"license": "AGPL-3",
}

View File

@@ -1,16 +1,16 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import api, models, _
from openerp.exceptions import UserError
from odoo import api, models, _
from odoo.exceptions import UserError
class ProcurementOrder(models.Model):
_inherit = 'procurement.order'
@api.model
def _prepare_auto_procurement_group_data(self, procurement):
def _prepare_auto_procurement_group_data(self):
name = self.env['ir.sequence'].next_by_code(
'procurement.group') or False
if not name:
@@ -19,13 +19,12 @@ class ProcurementOrder(models.Model):
'name': name
}
@api.model
def _assign(self, procurement):
res = super(ProcurementOrder, self)._assign(procurement)
if (procurement.rule_id and not procurement.group_id and
procurement.rule_id.auto_create_group):
group_data = self._prepare_auto_procurement_group_data(procurement)
@api.multi
def _assign(self):
res = super(ProcurementOrder, self)._assign()
if (self.rule_id and not self.group_id and
self.rule_id.auto_create_group):
group_data = self._prepare_auto_procurement_group_data()
group = self.env['procurement.group'].create(group_data)
procurement.group_id = group
self.group_id = group
return res

View File

@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import api, fields, models
from odoo import api, fields, models
class ProcurementRule(models.Model):

View File

@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# © 2017 Eficent Business and IT Consulting Services S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_auto_create

View File

@@ -2,7 +2,7 @@
# © 2017 Eficent Business and IT Consulting Services S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp.tests.common import TransactionCase
from odoo.tests.common import TransactionCase
class TestProcurementAutoCreateGroup(TransactionCase):
@@ -11,17 +11,24 @@ class TestProcurementAutoCreateGroup(TransactionCase):
self.po_model = self.env['procurement.order']
self.pr_model = self.env['procurement.rule']
self.product_12 = self.env.ref('product.product_product_12')
# Needed to avoid the dependency with stock:
if self.env.registry.models.get('stock.picking'):
picking_type_id = self.env.ref('stock.picking_type_internal').id
else:
picking_type_id = False
# Create rules:
self.no_auto_create = self.pr_model.create({
'name': 'rule without autocreate',
'auto_create_group': False,
'action': [],
'picking_type_id': picking_type_id,
})
self.auto_create = self.pr_model.create({
'name': 'rule with autocreate',
'auto_create_group': True,
'action': [],
'picking_type_id': picking_type_id,
})
def test_auto_create_group(self):
@@ -44,3 +51,10 @@ class TestProcurementAutoCreateGroup(TransactionCase):
})
self.assertTrue(proc2.group_id,
"Procurement Group has not been assigned.")
def test_onchange_method(self):
"""Test onchange method for procurement rule."""
proc_rule = self.auto_create
proc_rule.write({'group_propagation_option': 'none'})
proc_rule._onchange_group_propagation_option()
self.assertFalse(proc_rule.auto_create_group)