Skip to content

Commit

Permalink
Merge PR #795 into 12.0
Browse files Browse the repository at this point in the history
Signed-off-by hveficent
  • Loading branch information
OCA-git-bot committed Nov 27, 2019
2 parents ae79cfc + 045eefe commit 0e0c594
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 10 deletions.
2 changes: 1 addition & 1 deletion purchase_request/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
"data/purchase_request_sequence.xml",
"data/purchase_request_data.xml",
"reports/report_purchase_request.xml",
"wizard/purchase_request_line_make_purchase_order_view.xml",
"views/purchase_request_view.xml",
"views/purchase_request_line_view.xml",
"views/purchase_request_report.xml",
"views/product_template.xml",
"views/purchase_order_view.xml",
"views/stock_move_views.xml",
"wizard/purchase_request_line_make_purchase_order_view.xml",
],
'demo': [
"demo/purchase_request_demo.xml",
Expand Down
41 changes: 39 additions & 2 deletions purchase_request/tests/test_purchase_request_to_rfq.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,43 @@ def setUp(self):
'product_tmpl_id': self.service_product.product_tmpl_id.id,
})

def test_wizard_default_get(self):
# Check that correct create items by purchase.request
vals = {
'picking_type_id': self.env.ref('stock.picking_type_in').id,
'requested_by': SUPERUSER_ID,
'line_ids': [[0, 0, {
'product_id': self.env.ref('product.product_product_13').id,
'product_uom_id': self.env.ref('uom.product_uom_unit').id,
'product_qty': 2.0,
}]],
}
purchase_request1 = self.purchase_request.create(vals)
purchase_request1.button_approved()
vals = {
'supplier_id': self.env.ref('base.res_partner_1').id,
'line_ids': [[0, 0, {
'product_id': self.env.ref('product.product_product_13').id,
'product_uom_id': self.env.ref('uom.product_uom_unit').id,
'product_qty': 2.0,
}]],
}
purchase_request2 = self.purchase_request.create(vals)
vals = {
'supplier_id': self.env.ref('base.res_partner_1').id,
}
purchase_request1.button_approved()
purchase_request2.button_approved()
wiz_id = self.wiz.with_context(
active_model="purchase.request",
active_ids=[purchase_request1.id,
purchase_request2.id]).create(vals)
(purchase_request1 | purchase_request2).mapped('line_ids')
self.assertEquals(
(purchase_request1 | purchase_request2).mapped('line_ids'),
wiz_id.item_ids.mapped('line_id'),
'Should have same purchase request lines')

def test_purchase_request_to_purchase_rfq(self):
vals = {
'picking_type_id': self.env.ref('stock.picking_type_in').id,
Expand Down Expand Up @@ -264,7 +301,7 @@ def test_purchase_request_to_rfq_minimum_order_qty_existing_po(self):
}
wiz_id = self.wiz.with_context(
active_model="purchase.request.line",
active_ids=purchase_request_line1.id).create(vals)
active_ids=[purchase_request_line1.id]).create(vals)
wiz_id.make_purchase_order()
po = purchase_request_line1.purchase_lines[0].order_id
# Create Purchase Request
Expand All @@ -291,7 +328,7 @@ def test_purchase_request_to_rfq_minimum_order_qty_existing_po(self):
}
wiz_id = self.wiz.with_context(
active_model="purchase.request.line",
active_ids=purchase_request_line2.id).create(vals)
active_ids=[purchase_request_line2.id]).create(vals)
wiz_id.make_purchase_order()
# Check Purchase qty should be 6
po_line = purchase_request_line2.purchase_lines[0]
Expand Down
3 changes: 3 additions & 0 deletions purchase_request/views/purchase_request_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
type="object"
class="oe_highlight"
groups="purchase_request.group_purchase_request_manager"/>
<button name="%(action_purchase_request_line_make_purchase_order)d"
states="approved"
string="Create RFQ" type="action"/>
<button name="button_done"
states="approved"
string="Done"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,20 @@ def get_items(self, request_line_ids):

@api.model
def default_get(self, fields):
res = super(PurchaseRequestLineMakePurchaseOrder, self).default_get(
fields)
request_line_obj = self.env['purchase.request.line']
request_line_ids = self.env.context.get('active_ids', False)
res = super().default_get(fields)
active_model = self.env.context.get('active_model', False)
request_line_ids = []
if active_model == 'purchase.request.line':
request_line_ids += self.env.context.get('active_ids', [])
elif active_model == 'purchase.request':
request_ids = self.env.context.get('active_ids', False)
request_line_ids += self.env[active_model].browse(
request_ids).mapped('line_ids.id')
if not request_line_ids:
return res
assert active_model == 'purchase.request.line', \
'Bad context propagation'
res['item_ids'] = self.get_items(request_line_ids)
request_lines = request_line_obj.browse(request_line_ids)
request_lines = self.env['purchase.request.line'].browse(
request_line_ids)
supplier_ids = request_lines.mapped('supplier_id').ids
if len(supplier_ids) == 1:
res['supplier_id'] = supplier_ids[0]
Expand Down

0 comments on commit 0e0c594

Please sign in to comment.