From aaa379647c85f50f2cd387d278a25159d72cd56e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Grand-Guillaume?= Date: Wed, 16 Jul 2014 14:33:13 +0200 Subject: [PATCH 1/4] Change default numbering of RMA to avoid crash on SQL unique constraint --- crm_claim_rma/crm_claim_rma.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/crm_claim_rma/crm_claim_rma.py b/crm_claim_rma/crm_claim_rma.py index 9fd9d63d..9fa0b43c 100644 --- a/crm_claim_rma/crm_claim_rma.py +++ b/crm_claim_rma/crm_claim_rma.py @@ -338,11 +338,6 @@ class claim_line(orm.Model): class crm_claim(orm.Model): _inherit = 'crm.claim' - def _get_sequence_number(self, cr, uid, context=None): - seq_obj = self.pool.get('ir.sequence') - res = seq_obj.get(cr, uid, 'crm.claim.rma', context=context) or '/' - return res - def _get_default_warehouse(self, cr, uid, context=None): user_obj = self.pool.get('res.users') user = user_obj.browse(cr, uid, uid, context=context) @@ -366,20 +361,13 @@ class crm_claim(orm.Model): res.append((claim.id, '[' + number + '] ' + claim.name)) return res - def create(self, cr, uid, vals, context=None): - if ('number' not in vals) or (vals.get('number') == '/'): - vals['number'] = self._get_sequence_number(cr, uid, - context=context) - new_id = super(crm_claim, self).create(cr, uid, vals, context=context) - return new_id - def copy_data(self, cr, uid, id, default=None, context=None): if default is None: default = {} std_default = { 'invoice_ids': False, 'picking_ids': False, - 'number': self._get_sequence_number(cr, uid, context=context), + 'number': self.pool['ir.sequence'].get(cr, uid, 'crm.claim.rma') } std_default.update(default) return super(crm_claim, self).copy_data( @@ -423,7 +411,8 @@ class crm_claim(orm.Model): } _defaults = { - 'number': '/', + 'number': lambda self, cr, uid, context: self.pool['ir.sequence'].get( + cr, uid, 'crm.claim.rma'), 'claim_type': 'customer', 'warehouse_id': _get_default_warehouse, } From 39fa48276dc4c2fbf29f4ef3e29b9870d4af099c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Grand-Guillaume?= Date: Wed, 16 Jul 2014 14:46:22 +0200 Subject: [PATCH 2/4] Clean a bit of PEP8 things --- crm_claim_rma/__openerp__.py | 2 +- crm_claim_rma/account_invoice.py | 2 +- crm_claim_rma/crm_claim_rma.py | 2 +- crm_claim_rma/wizard/claim_make_picking.py | 3 +-- crm_rma_advance_location/__init__.py | 5 ++-- crm_rma_advance_location/__openerp__.py | 23 +++++++++---------- .../wizard/claim_make_picking_from_picking.py | 11 +++++---- crm_rma_by_shop/__openerp__.py | 2 +- product_warranty/__openerp__.py | 2 +- product_warranty/res_company.py | 2 +- 10 files changed, 27 insertions(+), 27 deletions(-) diff --git a/crm_claim_rma/__openerp__.py b/crm_claim_rma/__openerp__.py index e1765888..56d036b2 100644 --- a/crm_claim_rma/__openerp__.py +++ b/crm_claim_rma/__openerp__.py @@ -43,7 +43,7 @@ It mainly contains the following features: * product refund * access to related customer data (orders, invoices, refunds, picking in/out) from a claim -* use the OpenERP chatter within team like in opportunity (reply to refer to +* use the OpenERP chatter within team like in opportunity (reply to refer to the team, not a person) Using this module makes the logistic flow of return this way: diff --git a/crm_claim_rma/account_invoice.py b/crm_claim_rma/account_invoice.py index cb5aef54..aab0b57c 100644 --- a/crm_claim_rma/account_invoice.py +++ b/crm_claim_rma/account_invoice.py @@ -75,7 +75,7 @@ class account_invoice(orm.Model): raise orm.except_orm( _('Error !'), _('A refund has already been created for this claim !')) - return [(0, 0, line) for line in new_lines] + return [(0, 0, l) for l in new_lines] def _prepare_refund(self, cr, uid, invoice, date=None, period_id=None, description=None, journal_id=None, context=None): diff --git a/crm_claim_rma/crm_claim_rma.py b/crm_claim_rma/crm_claim_rma.py index 9fa0b43c..e9179579 100644 --- a/crm_claim_rma/crm_claim_rma.py +++ b/crm_claim_rma/crm_claim_rma.py @@ -333,7 +333,7 @@ class claim_line(orm.Model): return True -#TODO add the option to split the claim_line in order to manage the same +# TODO add the option to split the claim_line in order to manage the same # product separately class crm_claim(orm.Model): _inherit = 'crm.claim' diff --git a/crm_claim_rma/wizard/claim_make_picking.py b/crm_claim_rma/wizard/claim_make_picking.py index c2f3ad7a..fb97602a 100644 --- a/crm_claim_rma/wizard/claim_make_picking.py +++ b/crm_claim_rma/wizard/claim_make_picking.py @@ -51,7 +51,7 @@ class claim_make_picking(orm.TransientModel): } def _get_claim_lines(self, cr, uid, context): - #TODO use custom states to show buttons of this wizard or not instead + # TODO use custom states to show buttons of this wizard or not instead # of raise an error if context is None: context = {} @@ -163,7 +163,6 @@ class claim_make_picking(orm.TransientModel): p_type = 'out' write_field = 'move_out_id' note = 'RMA picking out' - view_xml_id = 'stock_picking_form' else: p_type = 'in' write_field = 'move_in_id' diff --git a/crm_rma_advance_location/__init__.py b/crm_rma_advance_location/__init__.py index 12f46fc0..f8cc7f32 100644 --- a/crm_rma_advance_location/__init__.py +++ b/crm_rma_advance_location/__init__.py @@ -2,7 +2,7 @@ ############################################################################## # # Copyright 2013 Camptocamp -# Copyright 2009-2013 Akretion, +# Copyright 2009-2013 Akretion, # Author: Emmanuel Samyn, Raphaël Valyi, Sébastien Beau, Joel Grand-Guillaume # # This program is free software: you can redistribute it and/or modify @@ -20,5 +20,4 @@ # ############################################################################## from . import stock -from . import wizard - +from . import wizard \ No newline at end of file diff --git a/crm_rma_advance_location/__openerp__.py b/crm_rma_advance_location/__openerp__.py index c6abba12..4b6dc66e 100644 --- a/crm_rma_advance_location/__openerp__.py +++ b/crm_rma_advance_location/__openerp__.py @@ -2,7 +2,7 @@ ############################################################################## # # Copyright 2013 Camptocamp -# Copyright 2009-2013 Akretion, +# Copyright 2009-2013 Akretion, # Author: Emmanuel Samyn, Raphaël Valyi, Sébastien Beau, Joel Grand-Guillaume # # This program is free software: you can redistribute it and/or modify @@ -51,15 +51,14 @@ Using this module make the logistic flow of return a bit more complexe: WARNING: Use with caution, this module is currently not yet completely debugged and is waiting his author to be. """, - 'images': [], - 'demo': [], - 'data': [ - 'wizard/claim_make_picking_from_picking_view.xml', - 'wizard/claim_make_picking_view.xml', - 'stock_view.xml', - 'stock_data.xml', - 'claim_rma_view.xml', - ], - 'installable': True, - 'application': True, + 'images': [], + 'demo': [], + 'data': ['wizard/claim_make_picking_from_picking_view.xml', + 'wizard/claim_make_picking_view.xml', + 'stock_view.xml', + 'stock_data.xml', + 'claim_rma_view.xml', + ], + 'installable': True, + 'application': True, } diff --git a/crm_rma_advance_location/wizard/claim_make_picking_from_picking.py b/crm_rma_advance_location/wizard/claim_make_picking_from_picking.py index 192393a4..b8fd528e 100644 --- a/crm_rma_advance_location/wizard/claim_make_picking_from_picking.py +++ b/crm_rma_advance_location/wizard/claim_make_picking_from_picking.py @@ -21,7 +21,7 @@ #along with this program. If not, see . # ######################################################################### from openerp.osv import fields, orm -from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT +from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT from openerp import netsvc import time @@ -56,7 +56,8 @@ class claim_make_picking_from_picking(orm.TransientModel): # Get default source location def _get_source_loc(self, cr, uid, context): - if context is None: context = {} + if context is None: + context = {} warehouse_obj = self.pool.get('stock.warehouse') warehouse_id = self._get_default_warehouse(cr, uid, context=context) return warehouse_obj.read(cr, uid, @@ -64,7 +65,8 @@ class claim_make_picking_from_picking(orm.TransientModel): # Get default destination location def _get_dest_loc(self, cr, uid, context): - if context is None: context = {} + if context is None: + context = {} warehouse_id = self._get_default_warehouse(cr, uid, context=context) warehouse_obj = self.pool.get('stock.warehouse') if context.get('picking_type'): @@ -88,7 +90,8 @@ class claim_make_picking_from_picking(orm.TransientModel): picking_obj = self.pool.get('stock.picking') move_obj = self.pool.get('stock.move') view_obj = self.pool.get('ir.ui.view') - if context is None: context = {} + if context is None: + context = {} p_type = 'internal' if context.get('picking_type'): context_type = context.get('picking_type')[8:] diff --git a/crm_rma_by_shop/__openerp__.py b/crm_rma_by_shop/__openerp__.py index ac33a2ca..4a0b80c4 100644 --- a/crm_rma_by_shop/__openerp__.py +++ b/crm_rma_by_shop/__openerp__.py @@ -36,7 +36,7 @@ Claim improvements to use them by shops: * Add shop on claim * Add various filter in order to work on a basic "by shop" basis - Was originally designed for e-commerce purpose, but could probably do the trick + Was originally designed for e-commerce purpose, but could probably do the trick for other cases as well. """, diff --git a/product_warranty/__openerp__.py b/product_warranty/__openerp__.py index 6ffdaca7..f63f0296 100644 --- a/product_warranty/__openerp__.py +++ b/product_warranty/__openerp__.py @@ -51,7 +51,7 @@ Those informations are used in the RMA Claim (Product Return Management) module. 'test': [], 'installable': True, 'active': False, - 'certificate' : '', + 'certificate': '', 'images': ['images/product_warranty.png'], } diff --git a/product_warranty/res_company.py b/product_warranty/res_company.py index 30618813..a3625170 100644 --- a/product_warranty/res_company.py +++ b/product_warranty/res_company.py @@ -2,7 +2,7 @@ ############################################################################## # # Copyright 2013 Camptocamp -# Copyright 2009-2013 Akretion, +# Copyright 2009-2013 Akretion, # Author: Emmanuel Samyn, Raphaël Valyi, Sébastien Beau, Joel Grand-Guillaume # # This program is free software: you can redistribute it and/or modify From fdfbd400964a49197d6fb08d4bbe3b19b1fa1671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Grand-Guillaume?= Date: Wed, 16 Jul 2014 15:06:48 +0200 Subject: [PATCH 3/4] Revert "Change default numbering of RMA to avoid crash on SQL unique constraint" This reverts commit aaa379647c85f50f2cd387d278a25159d72cd56e. --- crm_claim_rma/crm_claim_rma.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/crm_claim_rma/crm_claim_rma.py b/crm_claim_rma/crm_claim_rma.py index e9179579..dd30a00b 100644 --- a/crm_claim_rma/crm_claim_rma.py +++ b/crm_claim_rma/crm_claim_rma.py @@ -338,6 +338,11 @@ class claim_line(orm.Model): class crm_claim(orm.Model): _inherit = 'crm.claim' + def _get_sequence_number(self, cr, uid, context=None): + seq_obj = self.pool.get('ir.sequence') + res = seq_obj.get(cr, uid, 'crm.claim.rma', context=context) or '/' + return res + def _get_default_warehouse(self, cr, uid, context=None): user_obj = self.pool.get('res.users') user = user_obj.browse(cr, uid, uid, context=context) @@ -361,13 +366,20 @@ class crm_claim(orm.Model): res.append((claim.id, '[' + number + '] ' + claim.name)) return res + def create(self, cr, uid, vals, context=None): + if ('number' not in vals) or (vals.get('number') == '/'): + vals['number'] = self._get_sequence_number(cr, uid, + context=context) + new_id = super(crm_claim, self).create(cr, uid, vals, context=context) + return new_id + def copy_data(self, cr, uid, id, default=None, context=None): if default is None: default = {} std_default = { 'invoice_ids': False, 'picking_ids': False, - 'number': self.pool['ir.sequence'].get(cr, uid, 'crm.claim.rma') + 'number': self._get_sequence_number(cr, uid, context=context), } std_default.update(default) return super(crm_claim, self).copy_data( @@ -411,8 +423,7 @@ class crm_claim(orm.Model): } _defaults = { - 'number': lambda self, cr, uid, context: self.pool['ir.sequence'].get( - cr, uid, 'crm.claim.rma'), + 'number': '/', 'claim_type': 'customer', 'warehouse_id': _get_default_warehouse, } From 4d4a964a71cc5f0df2b781e36d9f988ae4d1a446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Grand-Guillaume?= Date: Wed, 16 Jul 2014 15:10:46 +0200 Subject: [PATCH 4/4] Add init method to initialize a value in claim 'number' (avoiding tests to crash) --- crm_claim_rma/crm_claim_rma.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crm_claim_rma/crm_claim_rma.py b/crm_claim_rma/crm_claim_rma.py index dd30a00b..e62d7276 100644 --- a/crm_claim_rma/crm_claim_rma.py +++ b/crm_claim_rma/crm_claim_rma.py @@ -338,6 +338,12 @@ class claim_line(orm.Model): class crm_claim(orm.Model): _inherit = 'crm.claim' + def init(self, cr): + cr.execute(""" + UPDATE "crm_claim" SET "number"=id::varchar WHERE ("number" is NULL) + OR ("number" = '/'); + """) + def _get_sequence_number(self, cr, uid, context=None): seq_obj = self.pool.get('ir.sequence') res = seq_obj.get(cr, uid, 'crm.claim.rma', context=context) or '/'