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

[ADD] mrp_supplier_price_generate_structure #97

Open
wants to merge 1 commit into
base: 12.0
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
40 changes: 40 additions & 0 deletions mrp_supplier_price_generate_structure/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
================================================================
Glue module mrp_supplier_price mrp_production_generate_structure
================================================================

.. |badge1| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

|badge1|

Extend mrp_production_generate_structure features using data provide by mrp_supplier_price module

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/avanzosc/odoo-addons/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 <https://github.com/avanzosc/mrp-addons/issues/new?body=module:%20mrp_supplier_price_generate_structure%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* AvanzOSC

Contributors
~~~~~~~~~~~~

* Mikel Arregi <mikelarregi@avanzosc.es>
* Ana Juaristi <anajuaristi@avanzosc.es>
1 change: 1 addition & 0 deletions mrp_supplier_price_generate_structure/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions mrp_supplier_price_generate_structure/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2021 Mikel Arregi Etxaniz - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
{
"name": "Glue module mrp_supplier_price mrp_production_generate_structure",
"version": "12.0.1.0.0",
"license": "AGPL-3",
"depends": [
"mrp_supplier_price", "mrp_production_generate_structure",
],
"author": "AvanzOSC",
"website": "http://www.avanzosc.es",
"category": "Tools",
"data": [

],
'demo': [],
'installable': True,
'auto_install': False,
}
2 changes: 2 additions & 0 deletions mrp_supplier_price_generate_structure/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import stock_rule
from . import mrp_production_product_line
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2021 Mikel Arregi Etxaniz - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import models


class MrpProductionProductLine(models.Model):
_inherit = 'mrp.production.product.line'

def _get_po_values(self, rule):
res = super()._get_po_values(rule)
res.update({'partner_id': self.supplier_id.id})
return res

def create_automatic_purchase_order(self, origin_manufacture_order, level):
if self.supplier_id not in self.product_id.seller_ids.mapped(
'name'):
self.env['product.supplierinfo'].create({
'name': self.supplier_id.id,
'product_tmpl_id': self.product_id.product_tmpl_id.id,
})
return super().create_automatic_purchase_order(
origin_manufacture_order, level)
14 changes: 14 additions & 0 deletions mrp_supplier_price_generate_structure/models/stock_rule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2021 Mikel Arregi Etxaniz - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, models


class StockRule(models.Model):
_inherit = "stock.rule"

@api.multi
def _make_po_select_supplier(self, values, suppliers):
partner_id = values.get('partner_id')
if partner_id:
return suppliers.filtered(lambda x: x.name.id == partner_id)[0]
return super()._make_po_select_supplier(values, suppliers)
1 change: 1 addition & 0 deletions mrp_supplier_price_generate_structure/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_mrp_supplier_price_generate_structure
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Copyright 2021 Mikel Arregi - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo.tests import common
from odoo.exceptions import UserError


@common.at_install(False)
@common.post_install(True)
class MrpSupplierPriceGenerateStructureTest(common.SavepointCase):

@classmethod
def setUpClass(cls):
super(MrpSupplierPriceGenerateStructureTest, cls).setUpClass()
cls.mrp_production_model = cls.env['mrp.production']
cls.bom_model = cls.env['mrp.bom']
cls.product_model = cls.env['product.product']
cls.buy_route = cls.env.ref("purchase_stock.route_warehouse0_buy")
cls.supplier = cls.env['res.partner'].create({
'name': 'Supplier Test',
'supplier': True,
})
cls.supplier2 = cls.env['res.partner'].create({
'name': 'Supplier Test2',
'supplier': True,
})
cls.supplier3 = cls.env['res.partner'].create({
'name': 'Supplier Test3',
'supplier': True,
})
bom_product = cls.product_model.create({
'name': 'BoM product',
})
cls.component1 = cls.product_model.create({
'name': 'Component1',
'standard_price': 10.0,
})
cls.component2 = cls.product_model.create({
'name': 'Component2',
'standard_price': 15.0,
'route_ids': [(4, cls.buy_route.id)],
})
cls.env['product.supplierinfo'].create({
'name': cls.supplier.id,
'product_tmpl_id': cls.component2.product_tmpl_id.id,
'min_qty': 1.0,
'price': 10.0,
})
cls.env['product.supplierinfo'].create({
'name': cls.supplier.id,
'product_tmpl_id': cls.component2.product_tmpl_id.id,
'min_qty': 10.0,
'price': 8.0,
})
cls.env['product.supplierinfo'].create({
'name': cls.supplier2.id,
'product_tmpl_id': cls.component2.product_tmpl_id.id,
'min_qty': 10.0,
'price': 8.0,
})
vals = {
'product_tmpl_id': bom_product.product_tmpl_id.id,
'product_id': bom_product.id,
'bom_line_ids':
[(0, 0, {'product_id': cls.component1.id,
'product_qty': 2.0}),
(0, 0, {'product_id': cls.component2.id,
'product_qty': 12.0}),
(0, 0, {'product_id': cls.component2.id,
'product_qty': 8.0}),
(0, 0, {'product_id': cls.component2.id,
'product_qty': 4.0}),
],
}
cls.mrp_bom = cls.bom_model.create(vals)
cls.production = cls.mrp_production_model.create({
'product_id': bom_product.id,
'product_uom_id': bom_product.uom_id.id,
'bom_id': cls.mrp_bom.id,
})

def test_mrp_production(self):
self.production.action_compute()
count = 0
for line in self.production.product_line_ids:
if line.product_id.id == self.component2.id and count==0:
line.supplier_id = self.supplier2.id
line.button_create_purchase_manufacturing_order()
self.assertTrue(
line.purchase_order_line_id.order_id.partner_id ==
self.supplier2)
count += 1
elif line.product_id.id == self.component2.id and count==1:
line.supplier_id = self.supplier3.id
line.button_create_purchase_manufacturing_order()
self.assertTrue(
line.purchase_order_line_id.order_id.partner_id ==
self.supplier3)
count += 1
elif line.product_id.id == self.component2.id:
line.button_create_purchase_manufacturing_order()
self.assertTrue(
line.purchase_order_line_id.order_id.partner_id ==
self.supplier)
self.assertTrue(self.supplier3 in self.component2.seller_ids.mapped(
'name'))