[REF] crm_rma_lot_mass_return: reverse some changes

This commit is contained in:
Osval Reyes
2015-11-19 15:33:16 -04:30
parent d1fb0f4517
commit b09e77dc77
4 changed files with 53 additions and 96 deletions

View File

@@ -43,7 +43,7 @@
'demo': [
'demo/stock_production_lot.xml',
'demo/purchase_order.xml',
# 'demo/sale_order.xml',
'demo/sale_order.xml',
'demo/transfer_details.xml',
],
'installable': True,

View File

@@ -3,7 +3,7 @@
#
# Copyright 2015 Vauxoo
# Author: Osval Reyes,
# Yanina Aular
# Yanina Aular
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as

View File

@@ -21,7 +21,6 @@
##############################################################################
from openerp.tests.common import TransactionCase
import re
class TestCrmRmaLotMassReturn2(TransactionCase):
@@ -58,6 +57,10 @@ class TestCrmRmaLotMassReturn2(TransactionCase):
})
def test_01_load_products(self):
# Before continue, invoice must be open to get a number value
# and this is needed by the wizard
wizard_id = self.metasearch_wizard.with_context({
'active_model': self.claim_id_1._name,
'active_id': self.claim_id_1.id,
@@ -90,43 +93,56 @@ class TestCrmRmaLotMassReturn2(TransactionCase):
for inv_line in self.sale_order.invoice_ids[0].invoice_line:
qty += inv_line.quantity
# Validate it has exactly as much records as the taken invoice has
self.assertEqual(len(lines_list_id), int(qty))
self.assertEqual(len(lines_list_id),
int(qty))
wizard_id._set_message()
wizard_id.add_claim_lines()
# 2 Macs
self.assertEqual(len(self.claim_id_1.claim_line_ids), 2)
self.assertEqual(len(self.claim_id_1.claim_line_ids),
2)
def test_02_load_products(self):
# Before continue, invoice must be open to get a number value
# and this is needed by the wizard
wizard_id = self.metasearch_wizard.with_context({
'active_model': self.claim_id_2._name,
'active_id': self.claim_id_2.id,
'active_ids': [self.claim_id_2.id]
}).create({})
line_str = self.sale_order.invoice_ids[0].number + '*5*A description\n'
# Get ids for invoice lines
lines_list_id = wizard_id.onchange_load_products(
line_str, [(6, 0, [])])['domain']['lines_list_id'][0][2]
self.sale_order.invoice_ids[0].number +
'*5*description here' + '\n',
[(6, 0, [])])['domain']['lines_list_id'][0][2]
option_ids = wizard_id.onchange_load_products(
line_str, [(6, 0, [])])['value']['option_ids'][0][2]
self.sale_order.invoice_ids[0].number +
'*5*description here' + '\n',
[(6, 0, [])])['value']['option_ids'][0][2]
wizard_id.option_ids = option_ids
cl_wizard = self.env['claim.line.wizard'].browse(lines_list_id)
mac0001 = cl_wizard.search([('lot_id.name', '=', 'MAC0001')])
mac0003 = cl_wizard.search([('lot_id.name', '=', 'MAC0003')])
toner0001 = cl_wizard.search([('product_id.name',
'=', 'Toner Cartridge')])
items_to_select = self.env['claim.line.wizard'].browse(lines_list_id)
mac0001 = items_to_select.search([('lot_id.name', '=', 'MAC0001')])
mac0003 = items_to_select.search([('lot_id.name', '=', 'MAC0003')])
toner0001 = items_to_select.search([('product_id.name',
'=', 'Toner Cartridge')])
toner0002 = toner0001[1]
toner0001 = toner0001[0]
ink0001 = cl_wizard.search([('product_id.name', '=', 'Ink Cartridge')])
ink0001 = items_to_select.search([('product_id.name',
'=', 'Ink Cartridge')])
wizard_id.lines_list_id = [(6, 0, [mac0001.id, mac0003.id,
toner0001.id, toner0002.id,
toner0001.id,
toner0002.id,
ink0001.id])]
# 1 Ink Cartridge, 2 Toner Cartridge, 1 iPad, 5 iMac
self.assertEqual(len(lines_list_id), 9)
@@ -134,76 +150,16 @@ class TestCrmRmaLotMassReturn2(TransactionCase):
for inv_line in self.sale_order.invoice_ids[0].invoice_line:
qty += inv_line.quantity
# Validate it has exactly as much records as the taken invoice has
self.assertEqual(len(lines_list_id), int(qty))
self.assertEqual(len(lines_list_id),
int(qty))
# wizard_id._set_message()
# regex = re.compile("The following Serial/Lot numbers"
# " won't be added.*MAC0001.*")
# self.assertTrue(regex.match(wizard_id.message))
wizard_id.add_claim_lines()
# 2 Macs
self.assertEqual(len(self.claim_id_2.claim_line_ids), 5)
def test_03_claim_line_creation_and_error_message(self):
"""
Challenge the wizard when a claim line is created, to set claim_origin
and the name correctly in a claim line itself, and also it tests the
message displayed to the user when is introduced an Serial/Lot numbers
that already is part of another claim.
"""
subject_list = self.env['claim.line'].SUBJECT_LIST
lot_name = "MAC0001"
subject_index = 3
scanned_data = lot_name + '*' + \
str(subject_index) + '*A short description to test\n'
wizard_id = self.metasearch_wizard.with_context({
'active_model': self.claim_id_2._name,
'active_id': self.claim_id_2.id,
'active_ids': [self.claim_id_2.id]
}).create({})
wizard_id.scan_data = scanned_data
# Get ids for invoice lines
lines_list_id = wizard_id.onchange_load_products(
scanned_data, [(6, 0, [])])['domain']['lines_list_id'][0][2]
wizard_id.option_id = wizard_id.onchange_load_products(
scanned_data, [(6, 0, [])])['value']['option_ids'][0][2]
items_to_select = self.env['claim.line.wizard'].browse(lines_list_id)
mac0001 = items_to_select.search([('lot_id.name', '=', lot_name)])
wizard_id.lines_list_id = [(6, 0, [mac0001.id])]
self.assertEqual(len(lines_list_id), 1)
wizard_id.add_claim_lines()
self.assertEqual(len(self.claim_id_2.claim_line_ids), 1)
line_id = self.claim_id_2.claim_line_ids
self.assertEqual(
subject_list[subject_index-1][0], line_id.claim_origin)
self.assertEqual(scanned_data, line_id.prodlot_id.name + '*'
+ str(subject_index) + '*' + line_id.name + '\n')
# create again the wizard
wizard_id = self.metasearch_wizard.with_context({
'active_model': self.claim_id_2._name,
'active_id': self.claim_id_2.id,
'active_ids': [self.claim_id_2.id]
}).create({})
wizard_id.scan_data = scanned_data
# Get ids for invoice lines
lines_list_id = wizard_id.onchange_load_products(
scanned_data, [(6, 0, [])])['domain']['lines_list_id'][0][2]
wizard_id.option_id = wizard_id.onchange_load_products(
scanned_data, [(6, 0, [])])['value']['option_ids'][0][2]
cl_wizard = self.env['claim.line.wizard'].browse(lines_list_id)
clw_id = cl_wizard.search([('lot_id.name', '=', lot_name)])
wizard_id.lines_list_id = [(6, 0, [clw_id.id])]
self.assertEqual(len(lines_list_id), 1)
wizard_id._set_message()
wizard_id.add_claim_lines()
self.assertEqual(len(self.claim_id_2.claim_line_ids), 1)
# if the message exists, then it's being displayed
regex = re.compile(".*" + lot_name + ".*")
self.assertTrue(regex.search(wizard_id.message))
self.assertEqual(len(self.claim_id_2.claim_line_ids),
5)

View File

@@ -109,6 +109,7 @@ class ReturnedLinesFromSerial(models.TransientModel):
else:
inv_line = claim_line_wizard.invoice_line_id
lot_id = False
line_rec = clima_line.create({
'claim_id': claim_id,
'claim_origin': claim_origin,
@@ -501,23 +502,23 @@ class ReturnedLinesFromSerial(models.TransientModel):
info = self.get_data_of_products(self.scan_data)
lot_ids = self._get_lot_ids()
lot_ids = [lid.id for lid in lot_ids]
clw_ids = set(self._get_lot_ids()) - \
valid_lot_ids = set(self._get_lot_ids()) - \
set(self._get_invalid_lots_set(lot_ids, True))
clw_ids = list(clw_ids)
valid_lot_ids = list(valid_lot_ids)
# It creates only those claim lines that have a valid production lot,
# i. e. not using in others claims
info = dict(info)
if clw_ids:
for clw_id in clw_ids:
product_id = clw_id.product_id
if valid_lot_ids:
for lot_id in valid_lot_ids:
product_id = lot_id.product_id
claim_line_info = False
if clw_id.lot_id.name in info:
claim_line_info = info.get(clw_id.lot_id.name, False)
elif clw_id.invoice_line_id.invoice_id.number in info:
if lot_id.name in info:
claim_line_info = info.get(lot_id.name, False)
elif lot_id.invoice_line_id.invoice_id.number in info:
claim_line_info = \
info.get(clw_id.invoice_line_id.invoice_id.number,
info.get(lot_id.invoice_line_id.invoice_id.number,
False)
num = claim_line_info and claim_line_info[0] or '0'
@@ -533,7 +534,7 @@ class ReturnedLinesFromSerial(models.TransientModel):
self.create_claim_line(self.env.context.get('active_id'),
self.env[
'claim.line']._get_subject(num),
product_id, clw_id, 1, name)
product_id, lot_id, 1, name)
# normal execution
self.action_cancel()