diff --git a/crm_claim_rma/__openerp__.py b/crm_claim_rma/__openerp__.py index 735e87ae..a0417879 100644 --- a/crm_claim_rma/__openerp__.py +++ b/crm_claim_rma/__openerp__.py @@ -81,6 +81,7 @@ Contributors: 'stock', 'crm_claim', 'crm_claim_code', + 'crm_claim_type', 'product_warranty', ], 'data': [ diff --git a/crm_claim_rma/models/crm_claim_rma.py b/crm_claim_rma/models/crm_claim_rma.py index 88f88647..33b81d64 100644 --- a/crm_claim_rma/models/crm_claim_rma.py +++ b/crm_claim_rma/models/crm_claim_rma.py @@ -220,10 +220,15 @@ class ClaimLine(models.Model): if not date_invoice: raise InvoiceNoDate - warning = _(self.WARRANT_COMMENT['not_define']) + warning = 'not_define' date_invoice = datetime.strptime(date_invoice, DEFAULT_SERVER_DATE_FORMAT) - if claim_type == 'supplier': + + if isinstance(claim_type, self.env['crm.claim.type'].__class__): + claim_type = claim_type.id + + if claim_type == self.env.ref('crm_claim_type.' + 'crm_claim_type_supplier').id: try: warranty_duration = product.seller_ids[0].warranty_duration except IndexError: @@ -236,9 +241,9 @@ class ClaimLine(models.Model): claim_date = datetime.strptime(claim_date, DEFAULT_SERVER_DATETIME_FORMAT) if limit < claim_date: - warning = _(self.WARRANT_COMMENT['expired']) + warning = 'expired' else: - warning = _(self.WARRANT_COMMENT['valid']) + warning = 'valid' return {'guarantee_limit': limit.strftime(DEFAULT_SERVER_DATE_FORMAT), 'warning': warning} @@ -278,7 +283,15 @@ class ClaimLine(models.Model): for a return. Always take 'Supplier' one when return type different from company. """ - location_dest_id = warehouse.lot_stock_id + if isinstance(warehouse, int): + location_dest_id = self.env['stock.warehouse']\ + .browse(warehouse).lot_stock_id + else: + location_dest_id = warehouse.lot_stock_id + + if isinstance(product, int): + product = self.env['product.product']\ + .browse(product) try: seller = product.seller_ids[0] if seller.warranty_return_partner != 'company': @@ -419,15 +432,6 @@ class CrmClaim(models.Model): std_default.update(default) return super(CrmClaim, self).copy_data(std_default) - claim_type = fields.Selection( - [('customer', 'Customer'), - ('supplier', 'Supplier'), - ('other', 'Other')], - string='Claim type', - required=True, - default='customer', - help="Customer: from customer to company.\n " - "Supplier: from company to supplier.") claim_line_ids = fields.One2many('claim.line', 'claim_id', string='Claim lines') planned_revenue = fields.Float(string='Expected revenue') @@ -500,11 +504,10 @@ class CrmClaim(models.Model): } line.update(warranty_values(invoice_line.invoice_id, invoice_line.product_id)) - claim_lines.append([0, 0, line]) + claim_lines.append((0, 0, line)) - for line in claim_lines: value = self._convert_to_cache( - {'claim_line_ids': line}, validate=False) + {'claim_line_ids': claim_lines}, validate=False) self.update(value) if self.invoice_id: diff --git a/crm_claim_rma/test/test_invoice_refund.yml b/crm_claim_rma/test/test_invoice_refund.yml index 66624fac..cbe6bc4c 100644 --- a/crm_claim_rma/test/test_invoice_refund.yml +++ b/crm_claim_rma/test/test_invoice_refund.yml @@ -22,7 +22,7 @@ - !record {model: crm.claim, id: claim_refund}: name: 'Angry Customer' - claim_type: customer + claim_type: crm_claim_type.crm_claim_type_customer partner_id: base.res_partner_3 invoice_id: account_invoice_claim_refund stage_id: crm_claim.stage_claim1 @@ -53,4 +53,5 @@ assert len(refund_line_ids) == 2, "It contains 2 lines, as excepted" refund_lines = self.pool.get('account.invoice.line').browse(cr, uid, refund_line_ids) assert ref('product.product_product_4') in [refund_lines[0].product_id.id, refund_lines[1].product_id.id], "First line is checked" - assert ref('product.product_product_5') in [refund_lines[0].product_id.id, refund_lines[1].product_id.id], "Second line is checked" \ No newline at end of file + assert ref('product.product_product_5') in [refund_lines[0].product_id.id, refund_lines[1].product_id.id], "Second line is checked" + diff --git a/crm_claim_rma/tests/test_picking_creation.py b/crm_claim_rma/tests/test_picking_creation.py index 2ef489e6..ce09c56e 100644 --- a/crm_claim_rma/tests/test_picking_creation.py +++ b/crm_claim_rma/tests/test_picking_creation.py @@ -2,6 +2,8 @@ ############################################################################## # # Author: Yannick Vaucher +# Yanina Aular +# Copyright 2015 Vauxoo # Copyright 2014 Camptocamp SA # # This program is free software: you can redistribute it and/or modify @@ -21,16 +23,15 @@ from openerp.tests import common -class test_picking_creation(common.TransactionCase): +class TestPickingCreation(common.TransactionCase): + """ Test the correct pickings are created by the wizard. """ def setUp(self): - super(test_picking_creation, self).setUp() + super(TestPickingCreation, self).setUp() - self.WizardMakePicking = self.env['claim_make_picking.wizard'] - self.StockPicking = self.env['stock.picking'] - ClaimLine = self.env['claim.line'] - Claim = self.env['crm.claim'] + self.wizard_make_picking = self.env['claim_make_picking.wizard'] + claim = self.env['crm.claim'] self.product_id = self.env.ref('product.product_product_4') @@ -39,41 +40,44 @@ class test_picking_creation(common.TransactionCase): self.customer_location_id = self.env.ref( 'stock.stock_location_customers') + sale_order_agrolait_demo = self.env.ref('sale.sale_order_1') + self.assertTrue(sale_order_agrolait_demo.invoice_ids, + "The Order Sale of Agrolait not have Invoice") + invoice_agrolait = sale_order_agrolait_demo.invoice_ids[0] + invoice_agrolait.\ + signal_workflow('invoice_open') + # Create the claim with a claim line - self.claim_id = Claim.create( + self.claim_id = claim.create( { 'name': 'TEST CLAIM', - 'number': 'TEST CLAIM', - 'claim_type': 'customer', + 'code': '/', + 'claim_type': self.env.ref('crm_claim_type.' + 'crm_claim_type_customer').id, 'delivery_address_id': self.partner_id.id, + 'partner_id': self.env.ref('base.res_partner_2').id, + 'invoice_id': invoice_agrolait.id, }) - + self.claim_id.with_context({'create_lines': True}).\ + _onchange_invoice_warehouse_type_date() self.warehouse_id = self.claim_id.warehouse_id - self.claim_line_id = ClaimLine.create( - { - 'name': 'TEST CLAIM LINE', - 'claim_origine': 'none', - 'product_id': self.product_id.id, - 'claim_id': self.claim_id.id, - 'location_dest_id': self.warehouse_id.lot_stock_id.id, - }) def test_00_new_product_return(self): """Test wizard creates a correct picking for product return """ - wizard = self.WizardMakePicking.with_context({ + wizard = self.wizard_make_picking.with_context({ 'active_id': self.claim_id.id, 'partner_id': self.partner_id.id, 'warehouse_id': self.warehouse_id.id, 'picking_type': 'in', + 'product_return': True, }).create({}) wizard.action_create_picking() self.assertEquals(len(self.claim_id.picking_ids), 1, "Incorrect number of pickings created") picking = self.claim_id.picking_ids[0] - self.assertEquals(picking.location_id, self.customer_location_id, "Incorrect source location") self.assertEquals(picking.location_dest_id, @@ -85,8 +89,8 @@ class test_picking_creation(common.TransactionCase): """ - WizardChangeProductQty = self.env['stock.change.product.qty'] - wizard_chg_qty = WizardChangeProductQty.with_context({ + wizardchangeproductqty = self.env['stock.change.product.qty'] + wizard_chg_qty = wizardchangeproductqty.with_context({ 'active_id': self.product_id.id, }).create({ 'product_id': self.product_id.id, @@ -95,7 +99,7 @@ class test_picking_creation(common.TransactionCase): wizard_chg_qty.change_product_qty() - wizard = self.WizardMakePicking.with_context({ + wizard = self.wizard_make_picking.with_context({ 'active_id': self.claim_id.id, 'partner_id': self.partner_id.id, 'warehouse_id': self.warehouse_id.id, @@ -111,3 +115,30 @@ class test_picking_creation(common.TransactionCase): "Incorrect source location") self.assertEquals(picking.location_dest_id, self.customer_location_id, "Incorrect destination location") + + def test_02_new_product_return(self): + """Test wizard creates a correct picking for product return + + """ + company = self.env.ref('base.main_company') + warehouse_obj = self.env['stock.warehouse'] + warehouse_rec = \ + warehouse_obj.search([('company_id', + '=', company.id)])[0] + wizard = self.wizard_make_picking.with_context({ + 'active_id': self.claim_id.id, + 'partner_id': self.partner_id.id, + 'warehouse_id': self.warehouse_id.id, + 'picking_type': warehouse_rec.in_type_id.id, + }).create({}) + wizard.action_create_picking() + + self.assertEquals(len(self.claim_id.picking_ids), 1, + "Incorrect number of pickings created") + picking = self.claim_id.picking_ids[0] + + self.assertEquals(picking.location_id, self.customer_location_id, + "Incorrect source location") + self.assertEquals(picking.location_dest_id, + self.warehouse_id.lot_stock_id, + "Incorrect destination location") diff --git a/crm_claim_rma/views/crm_claim_rma.xml b/crm_claim_rma/views/crm_claim_rma.xml index 84c60106..65f0e54f 100644 --- a/crm_claim_rma/views/crm_claim_rma.xml +++ b/crm_claim_rma/views/crm_claim_rma.xml @@ -60,9 +60,9 @@ - - - + + +