[IMP] stock_orderpoint_purchase_link: black, isort

This commit is contained in:
Joan Sisquella
2020-03-06 10:59:37 +01:00
committed by Dũng (Trần Đình)
parent 0c7d8fa2db
commit d091654ebd
6 changed files with 86 additions and 85 deletions

View File

@@ -1,2 +1 @@
from . import models

View File

@@ -7,16 +7,10 @@
"version": "12.0.1.0.0",
"license": "LGPL-3",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"author": "Eficent, "
"Odoo Community Association (OCA)",
"author": "Eficent, " "Odoo Community Association (OCA)",
"category": "Warehouse Management",
"depends": [
"stock_orderpoint_move_link",
"purchase_stock",
],
"data": [
"views/purchase_order_views.xml",
],
"depends": ["stock_orderpoint_move_link", "purchase_stock"],
"data": ["views/purchase_order_views.xml"],
"installable": True,
"auto_install": True,
}

View File

@@ -5,10 +5,11 @@ from odoo import fields, models
class PurchaseOrderLine(models.Model):
_inherit = 'purchase.order.line'
_inherit = "purchase.order.line"
orderpoint_ids = fields.Many2many(
comodel_name='stock.warehouse.orderpoint',
string='Orderpoints', copy=False,
comodel_name="stock.warehouse.orderpoint",
string="Orderpoints",
copy=False,
readonly=True,
)

View File

@@ -5,31 +5,31 @@ from odoo import models
class StockRule(models.Model):
_inherit = 'stock.rule'
_inherit = "stock.rule"
def _prepare_purchase_order_line(self, product_id, product_qty,
product_uom, values, po, partner):
def _prepare_purchase_order_line(
self, product_id, product_qty, product_uom, values, po, partner
):
vals = super()._prepare_purchase_order_line(
product_id, product_qty, product_uom, values, po, partner)
product_id, product_qty, product_uom, values, po, partner
)
# If the procurement was run directly by a reordering rule.
if 'orderpoint_id' in values:
vals['orderpoint_ids'] = [
(4, values['orderpoint_id'].id)]
if "orderpoint_id" in values:
vals["orderpoint_ids"] = [(4, values["orderpoint_id"].id)]
# If the procurement was run by a stock move.
elif 'orderpoint_ids' in values:
vals['orderpoint_ids'] = [(4, o.id)
for o in values['orderpoint_ids']]
elif "orderpoint_ids" in values:
vals["orderpoint_ids"] = [(4, o.id) for o in values["orderpoint_ids"]]
return vals
def _update_purchase_order_line(self, product_id, product_qty, product_uom,
values, line, partner):
def _update_purchase_order_line(
self, product_id, product_qty, product_uom, values, line, partner
):
vals = super()._update_purchase_order_line(
product_id, product_qty, product_uom, values, line, partner)
if 'orderpoint_id' in values:
vals['orderpoint_ids'] = [
(4, values['orderpoint_id'].id)]
product_id, product_qty, product_uom, values, line, partner
)
if "orderpoint_id" in values:
vals["orderpoint_ids"] = [(4, values["orderpoint_id"].id)]
# If the procurement was run by a stock move.
elif 'orderpoint_ids' in values:
vals['orderpoint_ids'] = [(4, o.id)
for o in values['orderpoint_ids']]
elif "orderpoint_ids" in values:
vals["orderpoint_ids"] = [(4, o.id) for o in values["orderpoint_ids"]]
return vals

View File

@@ -5,10 +5,11 @@ from odoo import fields, models
class StockWarehouseOrderpoint(models.Model):
_inherit = 'stock.warehouse.orderpoint'
_inherit = "stock.warehouse.orderpoint"
purchase_line_ids = fields.Many2many(
comodel_name='purchase.order.line',
string='Purchase Order Lines', copy=False,
comodel_name="purchase.order.line",
string="Purchase Order Lines",
copy=False,
readonly=True,
)

View File

@@ -8,69 +8,75 @@ class TestOrderpointPurchaseLink(common.TransactionCase):
def setUp(self):
super(TestOrderpointPurchaseLink, self).setUp()
self.product_obj = self.env['product.product']
self.partner_obj = self.env['res.partner']
self.pol_obj = self.env['purchase.order.line']
self.location_obj = self.env['stock.location']
self.orderpoint_obj = self.env['stock.warehouse.orderpoint']
self.route_obj = self.env['stock.location.route']
self.rule_obj = self.env['stock.rule']
self.group_obj = self.env['procurement.group']
self.product_obj = self.env["product.product"]
self.partner_obj = self.env["res.partner"]
self.pol_obj = self.env["purchase.order.line"]
self.location_obj = self.env["stock.location"]
self.orderpoint_obj = self.env["stock.warehouse.orderpoint"]
self.route_obj = self.env["stock.location.route"]
self.rule_obj = self.env["stock.rule"]
self.group_obj = self.env["procurement.group"]
# WH and routes:
self.warehouse = self.env.ref('stock.warehouse0')
self.warehouse = self.env.ref("stock.warehouse0")
self.stock_location = self.warehouse.lot_stock_id
self.test_location = self.location_obj.create({
'name': 'Test',
'location_id': self.warehouse.view_location_id.id,
})
route_buy = self.env.ref('purchase_stock.route_warehouse0_buy').id
route_test = self.route_obj.create({
'name': 'Stock to Test',
}).id
self.rule_obj.create({
'name': 'Stock to Test',
'action': 'pull',
'procure_method': 'make_to_order',
'location_id': self.test_location.id,
'location_src_id': self.stock_location.id,
'route_id': route_test,
'picking_type_id': self.warehouse.int_type_id.id,
'warehouse_id': self.warehouse.id,
'group_propagation_option': 'none',
})
self.test_location = self.location_obj.create(
{"name": "Test", "location_id": self.warehouse.view_location_id.id}
)
route_buy = self.env.ref("purchase_stock.route_warehouse0_buy").id
route_test = self.route_obj.create({"name": "Stock to Test"}).id
self.rule_obj.create(
{
"name": "Stock to Test",
"action": "pull",
"procure_method": "make_to_order",
"location_id": self.test_location.id,
"location_src_id": self.stock_location.id,
"route_id": route_test,
"picking_type_id": self.warehouse.int_type_id.id,
"warehouse_id": self.warehouse.id,
"group_propagation_option": "none",
}
)
# Partners:
vendor1 = self.partner_obj.create({'name': 'Vendor 1'})
vendor1 = self.partner_obj.create({"name": "Vendor 1"})
# Create products:
self.tp1 = self.product_obj.create({
'name': 'Test Product 1',
'type': 'product',
'list_price': 150.0,
'route_ids': [(6, 0, [route_buy, route_test])],
'seller_ids': [(0, 0, {'name': vendor1.id, 'price': 20.0})],
})
self.tp1 = self.product_obj.create(
{
"name": "Test Product 1",
"type": "product",
"list_price": 150.0,
"route_ids": [(6, 0, [route_buy, route_test])],
"seller_ids": [(0, 0, {"name": vendor1.id, "price": 20.0})],
}
)
# Create Orderpoints:
self.op1 = self.orderpoint_obj.create({
'product_id': self.tp1.id,
'location_id': self.stock_location.id,
'product_min_qty': 5.0,
'product_max_qty': 20.0,
})
self.op2 = self.orderpoint_obj.create({
'product_id': self.tp1.id,
'location_id': self.test_location.id,
'product_min_qty': 5.0,
'product_max_qty': 20.0,
})
self.op1 = self.orderpoint_obj.create(
{
"product_id": self.tp1.id,
"location_id": self.stock_location.id,
"product_min_qty": 5.0,
"product_max_qty": 20.0,
}
)
self.op2 = self.orderpoint_obj.create(
{
"product_id": self.tp1.id,
"location_id": self.test_location.id,
"product_min_qty": 5.0,
"product_max_qty": 20.0,
}
)
def test_01_po_line_from_orderpoints(self):
"""Test that a PO line created/updated by two orderpoints keeps
the link with both of them."""
self.group_obj.run_scheduler()
po_line = self.env['purchase.order.line'].search(
[('product_id', '=', self.tp1.id)])
po_line = self.env["purchase.order.line"].search(
[("product_id", "=", self.tp1.id)]
)
self.assertTrue(po_line)
# Each orderpoint must have required 20.0 units:
self.assertEqual(po_line.product_qty, 40.0)