[REF] crm_rma_lot_mass_return: make improvements for the wizard, add tests to validate changes

This commit is contained in:
Osval Reyes
2015-11-19 15:43:35 -04:30
parent b09e77dc77
commit 0b92f3ff5e
5 changed files with 159 additions and 65 deletions

View File

@@ -161,8 +161,8 @@ msgstr "Escribir el número de serie o lote para buscar el producto."
#. module: crm_rma_lot_mass_return
#: view:returned.lines.from.serial.wizard:crm_rma_lot_mass_return.view_enter_product
msgid "You add new returns in claim, are you sure?."
msgstr "Agregarás nuevas devoluciones en el reclamo, ¿Estás seguro?"
msgid "You are about to add new lines to the claim, Do you want to continue?."
msgstr "Se agregarán nuevas neas a la reclamación, ¿Desea continuar?"
#. module: crm_rma_lot_mass_return
#: view:returned.lines.from.serial.wizard:crm_rma_lot_mass_return.view_enter_product
@@ -171,8 +171,8 @@ msgstr "Deberías usar ésta ventana"
#. module: crm_rma_lot_mass_return
#: view:returned.lines.from.serial.wizard:crm_rma_lot_mass_return.view_enter_product
msgid "_Validate"
msgstr "_Validar"
msgid "Add items to the claim"
msgstr "Añadir productos a la reclamación"
#. module: crm_rma_lot_mass_return
#: code:addons/crm_rma_lot_mass_return/wizards/returned_lines_from_serial.py:585

View File

@@ -20,6 +20,7 @@
#
##############################################################################
from datetime import date
from openerp.tests.common import TransactionCase
@@ -66,11 +67,6 @@ class TestCrmRmaLotMassReturn(TransactionCase):
self.assertEqual(res['res_model'], self.metasearch_wizard._name)
def test_02_load_products(self):
self.invoice_id.signal_workflow('invoice_open')
# Before continue, invoice must be open to get a number value
# and this is needed by the wizard
self.assertEqual(self.invoice_id.state, 'open')
wizard_id = self.metasearch_wizard.with_context({
'active_model': self.claim_id._name,
@@ -82,7 +78,10 @@ class TestCrmRmaLotMassReturn(TransactionCase):
lines_list_id = wizard_id.onchange_load_products(
self.invoice_id.number +
'*5*description here' + '\n' + self.lot_ids[0].name,
[(6, 0, [])])['domain']['lines_list_id'][0][2]
[(6, 0, [])])
lines_list_id = lines_list_id['domain']['lines_list_id'][0][2]
option_ids = wizard_id.onchange_load_products(
self.invoice_id.number, [(6, 0, [])])['value']['option_ids'][0][2]
@@ -107,6 +106,49 @@ class TestCrmRmaLotMassReturn(TransactionCase):
self.assertEqual(len(self.claim_id.claim_line_ids),
int(qty))
def sale_validate_invoice(self, sale):
sale_advance_obj = self.env['sale.advance.payment.inv']
context = {
'active_model': 'sale.order',
'active_ids': [sale.id],
'active_id': sale.id,
}
wizard_invoice_id = sale_advance_obj.with_context(context).create({
'advance_payment_method': 'all',
})
wizard_invoice_id.with_context(context).create_invoices()
invoice_id = sale.invoice_ids[0]
invoice_id.signal_workflow('invoice_open')
# check if invoice is open
self.assertEqual(invoice_id.state, 'open')
pay_account_id = self.env['account.account'].\
browse(self.ref("account.cash"))
journal_id = self.env['account.journal'].\
browse(self.ref("account.bank_journal"))
date_start = date.today().replace(day=1, month=1).strftime('%Y-%m-%d')
period_id = self.env['account.fiscalyear'].search(
[('date_start', '=', date_start)]).period_ids[8]
invoice_id.pay_and_reconcile(
invoice_id.amount_total, pay_account_id.id,
period_id.id, journal_id.id, pay_account_id.id,
period_id.id, journal_id.id,
name="Payment for Invoice")
# in order to proceed is necessary to get the sale order invoiced
# and the invoice paid as well
self.assertTrue(sale.invoiced)
self.assertEqual(invoice_id.state, 'paid')
return invoice_id
def create_sale_invoice(self):
sale_order_id = self.create_sale_order('manual')
@@ -150,8 +192,8 @@ class TestCrmRmaLotMassReturn(TransactionCase):
wizard_id.do_detailed_transfer()
sale_order_id.action_invoice_create()
invoice_id = sale_order_id.invoice_ids[0]
invoice_id.signal_workflow('invoice_open')
# Before continue, invoice must be open to get a number value
# and this is needed by the wizard
invoice_id = self.sale_validate_invoice(sale_order_id)
return invoice_id, lot_ids

View File

@@ -21,6 +21,7 @@
##############################################################################
from openerp.tests.common import TransactionCase
import re
class TestCrmRmaLotMassReturn2(TransactionCase):
@@ -57,10 +58,6 @@ 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,
@@ -93,56 +90,43 @@ 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(
self.sale_order.invoice_ids[0].number +
'*5*description here' + '\n',
[(6, 0, [])])['domain']['lines_list_id'][0][2]
line_str, [(6, 0, [])])['domain']['lines_list_id'][0][2]
option_ids = wizard_id.onchange_load_products(
self.sale_order.invoice_ids[0].number +
'*5*description here' + '\n',
[(6, 0, [])])['value']['option_ids'][0][2]
line_str, [(6, 0, [])])['value']['option_ids'][0][2]
wizard_id.option_ids = option_ids
cl_wizard = self.env['claim.line.wizard'].browse(lines_list_id)
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')])
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')])
toner0002 = toner0001[1]
toner0001 = toner0001[0]
ink0001 = items_to_select.search([('product_id.name',
'=', 'Ink Cartridge')])
ink0001 = cl_wizard.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)
@@ -150,16 +134,76 @@ 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.add_claim_lines()
# 2 Macs
self.assertEqual(len(self.claim_id_2.claim_line_ids), 5)
# wizard_id._set_message()
# regex = re.compile("The following Serial/Lot numbers"
# " won't be added.*MAC0001.*")
# self.assertTrue(regex.match(wizard_id.message))
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)
# 2 Macs
self.assertEqual(len(self.claim_id_2.claim_line_ids),
5)
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))

View File

@@ -109,7 +109,6 @@ 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,
@@ -502,23 +501,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]
valid_lot_ids = set(self._get_lot_ids()) - \
clw_ids = set(self._get_lot_ids()) - \
set(self._get_invalid_lots_set(lot_ids, True))
valid_lot_ids = list(valid_lot_ids)
clw_ids = list(clw_ids)
# It creates only those claim lines that have a valid production lot,
# i. e. not using in others claims
info = dict(info)
if valid_lot_ids:
for lot_id in valid_lot_ids:
product_id = lot_id.product_id
if clw_ids:
for clw_id in clw_ids:
product_id = clw_id.product_id
claim_line_info = False
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:
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:
claim_line_info = \
info.get(lot_id.invoice_line_id.invoice_id.number,
info.get(clw_id.invoice_line_id.invoice_id.number,
False)
num = claim_line_info and claim_line_info[0] or '0'
@@ -534,7 +533,16 @@ class ReturnedLinesFromSerial(models.TransientModel):
self.create_claim_line(self.env.context.get('active_id'),
self.env[
'claim.line']._get_subject(num),
product_id, lot_id, 1, name)
product_id, clw_id, 1, name)
# Clean items in wizard model
if len(clw_ids) == 1:
ids_to_delete = "(%s)" % str(clw_ids[0].id)
else:
ids_to_delete = "%s" % str(tuple([clw.id for clw in clw_ids]))
self._cr.execute("DELETE FROM claim_line_wizard where id IN %s"
% ids_to_delete)
# normal execution
self.action_cancel()

View File

@@ -38,9 +38,9 @@
<div class="row">
<div class="pull-right" name="buttons">
<button name="add_claim_lines"
help="Validate the actual picking, it will execute all the validations and the inventory will be affected"
confirm="You add new returns in claim, are you sure?."
string="_Validate" colspan="1" type="object" class="oe_highlight"/>
help="All the valid lines will be added to the claim"
confirm="You are about to add new lines to the claim, Do you want to continue?."
string="Add items to the claim" colspan="1" type="object" class="oe_highlight"/>
</div>
</div>
</div>