mirror of
https://github.com/OCA/rma.git
synced 2025-02-16 17:11:47 +02:00
[IMP] Second round of cleaning : base of PEP8, respect of community standard (orm.Model,..), move last unused wizard to crm_claim_ext
This commit is contained in:
@@ -41,6 +41,7 @@ author (Akretion) take a decision on them.
|
||||
'init_xml': [],
|
||||
'update_xml': [
|
||||
'crm_claim_ext_view.xml',
|
||||
'wizard/get_empty_serial_view.xml',
|
||||
# 'wizard/returned_lines_from_invoice_wizard_view.xml',
|
||||
# 'wizard/picking_from_returned_lines_wizard_view.xml',
|
||||
# 'wizard/refund_from_returned_lines_wizard_view.xml',
|
||||
|
||||
@@ -37,6 +37,11 @@ class crm_claim_ext(osv.osv):
|
||||
'canal_id': fields.many2one('res.partner.canal', 'Channel'),
|
||||
'som': fields.many2one('res.partner.som', 'State of Mind'),
|
||||
'product_exchange_ids': fields.one2many('product.exchange', 'claim_return_id', 'Product exchanges'),
|
||||
# Aftersale outsourcing
|
||||
# 'in_supplier_picking_id': fields.many2one('stock.picking', 'Return To Supplier Picking', required=False, select=True),
|
||||
# 'out_supplier_picking_id': fields.many2one('stock.picking', 'Return From Supplier Picking', required=False, select=True),
|
||||
|
||||
|
||||
}
|
||||
crm_claim_ext()
|
||||
|
||||
|
||||
@@ -23,4 +23,5 @@
|
||||
#import picking_from_returned_lines
|
||||
#import refund_from_returned_lines
|
||||
#import exchange_from_returned_lines
|
||||
#import picking_from_exchange_lines
|
||||
#import picking_from_exchange_lines
|
||||
from . import get_empty_serial
|
||||
@@ -20,10 +20,11 @@
|
||||
#along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
||||
#########################################################################
|
||||
|
||||
from osv import fields, osv
|
||||
from openerp.osv import fields, orm
|
||||
import pooler
|
||||
|
||||
class get_empty_serial(osv.osv_memory):
|
||||
|
||||
class get_empty_serial(orm.TransientModel):
|
||||
_name='get_empty_serial.wizard'
|
||||
_description='' # Get possible serial for this return based on claim partner, product, invoice
|
||||
_columns = {
|
||||
@@ -20,8 +20,8 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import wizard
|
||||
import crm_claim_rma
|
||||
import account_invoice
|
||||
import stock
|
||||
import res_company
|
||||
from . import wizard
|
||||
from . import crm_claim_rma
|
||||
from . import account_invoice
|
||||
from . import stock
|
||||
from . import res_company
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
#
|
||||
##############################################################################
|
||||
{
|
||||
'name': 'CRM Product Return',
|
||||
'version': '1.0',
|
||||
'name': 'Claim RMA (Product Return Management)',
|
||||
'version': '1.1',
|
||||
'category': 'Generic Modules/CRM & SRM',
|
||||
'description': """
|
||||
Management of Return Merchandise Authorization (RMA)
|
||||
@@ -48,7 +48,6 @@ It mainly contain the following features :
|
||||
'wizard/claim_make_picking_view.xml',
|
||||
'wizard/claim_make_picking_from_picking_view.xml',
|
||||
'wizard/returned_lines_from_serial_wizard_view.xml',
|
||||
'wizard/get_empty_serial_view.xml',
|
||||
'crm_claim_rma_view.xml',
|
||||
'security/ir.model.access.csv',
|
||||
'account_invoice_view.xml',
|
||||
|
||||
@@ -19,60 +19,72 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import fields, osv
|
||||
from openerp.osv import fields, orm
|
||||
from tools.translate import _
|
||||
|
||||
class account_invoice(osv.osv):
|
||||
|
||||
class account_invoice(orm.Model):
|
||||
|
||||
_inherit = "account.invoice"
|
||||
|
||||
|
||||
_columns = {
|
||||
'claim_id': fields.many2one('crm.claim', 'Claim'),
|
||||
}
|
||||
|
||||
def _get_cleanup_fields(self, cr, uid, context=None):
|
||||
fields = super(account_invoice, self)._get_cleanup_fields(cr, uid, context=context)
|
||||
fields = super(account_invoice, self)._get_cleanup_fields(cr, uid,
|
||||
context=context)
|
||||
fields = fields + ('claim_line_id',)
|
||||
return fields
|
||||
|
||||
def _refund_cleanup_lines(self, cr, uid, lines, context=None):
|
||||
if context is None: context = {}
|
||||
new_lines = []
|
||||
if context.get('claim_line_ids') and lines and 'product_id' in lines[0]:#check if is an invoice_line
|
||||
# check if is an invoice_line
|
||||
if context.get('claim_line_ids') and lines and 'product_id' in lines[0]:
|
||||
for claim_line_id in context.get('claim_line_ids'):
|
||||
claim_info = self.pool.get('claim.line').read(cr, uid, claim_line_id[1], ['invoice_line_id', 'product_returned_quantity', 'refund_line_id'], context=context)
|
||||
claim_info = self.pool.get('claim.line').read(cr, uid,
|
||||
claim_line_id[1],
|
||||
[
|
||||
'invoice_line_id',
|
||||
'product_returned_quantity',
|
||||
'refund_line_id'],
|
||||
context=context)
|
||||
if not claim_info['refund_line_id']:
|
||||
invoice_line_info = self.pool.get('account.invoice.line').browse(cr, uid, [claim_info['invoice_line_id'][0]], context=context)[0]
|
||||
inv_line_obj = self.pool.get('account.invoice.line')
|
||||
inv_line = inv_line_obj.browse(cr, uid,
|
||||
[claim_info['invoice_line_id'][0]],
|
||||
context=context)[0]
|
||||
clean_line = {}
|
||||
for field in invoice_line_info._all_columns.keys():
|
||||
if invoice_line_info._all_columns[field].column._type == 'many2one':
|
||||
clean_line[field] = invoice_line_info[field].id
|
||||
elif invoice_line_info._all_columns[field].column._type not in ['many2many','one2many']:
|
||||
clean_line[field] = invoice_line_info[field]
|
||||
column_type = inv_line._all_columns[field].column._type
|
||||
if column_type == 'many2one':
|
||||
clean_line[field] = inv_line[field].id
|
||||
elif column_type not in ['many2many','one2many']:
|
||||
clean_line[field] = inv_line[field]
|
||||
elif field == 'invoice_line_tax_id':
|
||||
tax_list = []
|
||||
for tax in invoice_line_info[field]:
|
||||
for tax in inv_line[field]:
|
||||
tax_list.append(tax.id)
|
||||
clean_line[field] = [(6,0, tax_list)]
|
||||
#invoice_line_info = self.pool.get('account.invoice.line').read(cr, uid, claim_info['invoice_line_id'][0], context=context)
|
||||
clean_line['quantity'] = claim_info['product_returned_quantity']
|
||||
clean_line['claim_line_id'] = [claim_line_id[1]]
|
||||
new_lines.append(clean_line)
|
||||
if not new_lines:
|
||||
#TODO use custom states to show button of this wizard or not instead of raise an error
|
||||
raise osv.except_osv(_('Error !'), _('A refund has already been created for this claim !'))
|
||||
#result = super(account_invoice, self)._refund_cleanup_lines(cr, uid, lines, context=context)
|
||||
# TODO use custom states to show button of this wizard or
|
||||
# not instead of raise an error
|
||||
raise osv.except_osv(_('Error !'),
|
||||
_('A refund has already been created for this claim !'))
|
||||
return map(lambda x: (0,0,x), new_lines)
|
||||
|
||||
def _prepare_refund(self, cr, uid, *args, **kwargs):
|
||||
result = super(account_invoice, self)._prepare_refund(cr, uid, *args, **kwargs)
|
||||
result = super(account_invoice, self)._prepare_refund(cr, uid,
|
||||
*args, **kwargs)
|
||||
if kwargs.get('context') and kwargs['context'].get('claim_id'):
|
||||
result['claim_id'] = kwargs['context']['claim_id']
|
||||
return result
|
||||
|
||||
class account_invoice_line(osv.osv):
|
||||
class account_invoice_line(orm.Model):
|
||||
|
||||
_inherit = "account.invoice.line"
|
||||
|
||||
@@ -81,7 +93,10 @@ class account_invoice_line(osv.osv):
|
||||
if vals.get('claim_line_id'):
|
||||
claim_line_id = vals['claim_line_id']
|
||||
del vals['claim_line_id']
|
||||
line_id = super(account_invoice_line, self).create(cr, uid, vals, context=context)
|
||||
line_id = super(account_invoice_line, self).create(cr, uid,
|
||||
vals, context=context)
|
||||
if claim_line_id:
|
||||
self.pool.get('claim.line').write(cr, uid, claim_line_id, {'refund_line_id': line_id}, context=context)
|
||||
claim_line_obj = self.pool.get('claim.line')
|
||||
claim_line_obj.write(cr, uid, claim_line_id,
|
||||
{'refund_line_id': line_id}, context=context)
|
||||
return line_id
|
||||
|
||||
@@ -21,14 +21,15 @@
|
||||
##############################################################################
|
||||
|
||||
from openerp.osv import fields, orm, osv
|
||||
from crm import crm
|
||||
# from crm import crm
|
||||
from datetime import datetime
|
||||
from dateutil.relativedelta import relativedelta
|
||||
import time
|
||||
from tools.translate import _
|
||||
from tools import DEFAULT_SERVER_DATE_FORMAT
|
||||
from tools.translate import _
|
||||
|
||||
|
||||
#TODO: REFACTOR IN A GENERIC MODULE
|
||||
class substate_substate(orm.Model):
|
||||
"""
|
||||
To precise a state (state=refused; substates= reason 1, 2,...)
|
||||
@@ -37,16 +38,23 @@ class substate_substate(orm.Model):
|
||||
_description = "substate that precise a given state"
|
||||
_columns = {
|
||||
'name': fields.char('Sub state', size=128, required=True),
|
||||
'substate_descr' : fields.text('Description', help="To give more information about the sub state"),
|
||||
'substate_descr' : fields.text('Description',
|
||||
help="To give more information about the sub state"),
|
||||
# ADD OBJECT TO FILTER
|
||||
}
|
||||
|
||||
|
||||
class claim_line(orm.Model):
|
||||
"""
|
||||
Class to handle a product return line (corresponding to one invoice line)
|
||||
"""
|
||||
_name = "claim.line"
|
||||
_description = "List of product to return"
|
||||
|
||||
# Comment written in a claim.line to know about the warranty status
|
||||
WARRANT_COMMENT = {
|
||||
'valid': "Valid",
|
||||
'expired': "Expired"}
|
||||
|
||||
# Method to calculate total amount of the line : qty*UP
|
||||
def _line_total_amount(self, cr, uid, ids, field_name, arg, context=None):
|
||||
@@ -58,37 +66,80 @@ class claim_line(orm.Model):
|
||||
_columns = {
|
||||
'name': fields.char('Description', size=64,required=True),
|
||||
'claim_origine': fields.selection([('none','Not specified'),
|
||||
('legal','Legal retractation'),
|
||||
('cancellation','Order cancellation'),
|
||||
('damaged','Damaged delivered product'),
|
||||
('error','Shipping error'),
|
||||
('exchange','Exchange request'),
|
||||
('lost','Lost during transport'),
|
||||
('other','Other')], 'Claim Subject', required=True, help="To describe the line product problem"),
|
||||
'claim_descr' : fields.text('Claim description', help="More precise description of the problem"),
|
||||
'product_id': fields.many2one('product.product', 'Product',help="Returned product"),
|
||||
'product_returned_quantity' : fields.float('Quantity', digits=(12,2), help="Quantity of product returned"),
|
||||
'unit_sale_price' : fields.float('Unit sale price', digits=(12,2), help="Unit sale price of the product. Auto filed if retrun done by invoice selection. BE CAREFUL AND CHECK the automatic value as don't take into account previous refounds, invoice discount, can be for 0 if product for free,..."),
|
||||
'return_value' : fields.function(_line_total_amount, method=True, string='Total return', type='float', help="Quantity returned * Unit sold price",),
|
||||
'prodlot_id': fields.many2one('stock.production.lot', 'Serial/Lot n°',help="The serial/lot of the returned product"),
|
||||
'applicable_guarantee': fields.selection([('us','Company'),('supplier','Supplier'),('brand','Brand manufacturer')], 'Warranty type'),# TODO: Replace with function field. type supplier might generate an auto draft forward to the supplier
|
||||
'guarantee_limit': fields.date('Warranty limit', help="The warranty limit is computed as: invoice date + warranty defined on selected product.", readonly=True),
|
||||
'warning': fields.char('Warranty', size=64, readonly=True,help="If warranty has expired"),
|
||||
'warranty_type': fields.char('Warranty type', size=64, readonly=True,help="from product form"),
|
||||
"warranty_return_partner" : fields.many2one('res.partner', 'Warranty return',help="Where the customer has to send back the product(s)"),
|
||||
'claim_id': fields.many2one('crm.claim', 'Related claim',help="To link to the case.claim object"),
|
||||
('legal','Legal retractation'),
|
||||
('cancellation','Order cancellation'),
|
||||
('damaged','Damaged delivered product'),
|
||||
('error','Shipping error'),
|
||||
('exchange','Exchange request'),
|
||||
('lost','Lost during transport'),
|
||||
('other','Other')],
|
||||
'Claim Subject',
|
||||
required=True,
|
||||
help="To describe the line product problem"),
|
||||
'claim_descr' : fields.text('Claim description',
|
||||
help="More precise description of the problem"),
|
||||
'product_id': fields.many2one('product.product', 'Product',
|
||||
help="Returned product"),
|
||||
'product_returned_quantity' : fields.float('Quantity', digits=(12,2),
|
||||
help="Quantity of product returned"),
|
||||
'unit_sale_price' : fields.float('Unit sale price', digits=(12,2),
|
||||
help="Unit sale price of the product. Auto filed if retrun done by"
|
||||
" invoice selection. BE CAREFUL AND CHECK the automatic value "
|
||||
"as don't take into account previous refounds, invoice "
|
||||
"discount, can be for 0 if product for free,..."),
|
||||
'return_value' : fields.function(_line_total_amount, method=True,
|
||||
string='Total return',
|
||||
type='float',
|
||||
help="Quantity returned * Unit sold price",),
|
||||
'prodlot_id': fields.many2one('stock.production.lot', 'Serial/Lot n°',
|
||||
help="The serial/lot of the returned product"),
|
||||
'applicable_guarantee': fields.selection(
|
||||
[
|
||||
('us','Company'),
|
||||
('supplier','Supplier'),
|
||||
('brand','Brand manufacturer')],
|
||||
'Warranty type'),
|
||||
'guarantee_limit': fields.date('Warranty limit',
|
||||
readonly=True,
|
||||
help="The warranty limit is computed as: invoice date + warranty "
|
||||
"defined on selected product."),
|
||||
'warning': fields.char('Warranty', size=64,
|
||||
readonly=True,
|
||||
help="If warranty has expired"),
|
||||
'warranty_type': fields.char('Warranty type',
|
||||
size=64,
|
||||
readonly=True,
|
||||
help="From product form"),
|
||||
"warranty_return_partner" : fields.many2one('res.partner',
|
||||
'Warranty return',
|
||||
help="Where the customer has to send back the product(s)"),
|
||||
'claim_id': fields.many2one('crm.claim', 'Related claim',
|
||||
help="To link to the case.claim object"),
|
||||
'state' : fields.selection([('draft','Draft'),
|
||||
('refused','Refused'),
|
||||
('confirmed','Confirmed, waiting for product'),
|
||||
('in_to_control','Received, to control'),
|
||||
('in_to_treate','Controlled, to treate'),
|
||||
('treated','Treated')], 'State'),
|
||||
'substate_id': fields.many2one('substate.substate', 'Sub state',help="Select a sub state to precise the standard state. Example 1: state = refused; substate could be warranty over, not in warranty, no problem,... . Example 2: state = to treate; substate could be to refund, to exchange, to repair,..."),
|
||||
'last_state_change': fields.date('Last change', help="To set the last state / substate change"),
|
||||
'invoice_line_id': fields.many2one('account.invoice.line', 'Invoice Line', help='The invoice line related to the returned product'),
|
||||
'refund_line_id': fields.many2one('account.invoice.line', 'Refund Line', help='The refund line related to the returned product'),
|
||||
'move_in_id': fields.many2one('stock.move', 'Move Line from picking in', help='The move line related to the returned product'),
|
||||
'move_out_id': fields.many2one('stock.move', 'Move Line from picking out', help='The move line related to the returned product'),
|
||||
'substate_id': fields.many2one('substate.substate', 'Sub state',
|
||||
help="Select a sub state to precise the standard state. Example 1: "
|
||||
"state = refused; substate could be warranty over, not in "
|
||||
"warranty, no problem,... . Example 2: state = to treate; "
|
||||
"substate could be to refund, to exchange, to repair,..."),
|
||||
'last_state_change': fields.date('Last change',
|
||||
help="To set the last state / substate change"),
|
||||
'invoice_line_id': fields.many2one('account.invoice.line',
|
||||
'Invoice Line',
|
||||
help='The invoice line related to the returned product'),
|
||||
'refund_line_id': fields.many2one('account.invoice.line',
|
||||
'Refund Line',
|
||||
help='The refund line related to the returned product'),
|
||||
'move_in_id': fields.many2one('stock.move',
|
||||
'Move Line from picking in',
|
||||
help='The move line related to the returned product'),
|
||||
'move_out_id': fields.many2one('stock.move',
|
||||
'Move Line from picking out',
|
||||
help='The move line related to the returned product'),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
@@ -100,29 +151,41 @@ class claim_line(orm.Model):
|
||||
def set_warranty_limit(self, cr, uid, ids, claim_line, context=None):
|
||||
date_invoice = claim_line.invoice_line_id.invoice_id.date_invoice
|
||||
if date_invoice:
|
||||
warning = "Valid"
|
||||
warning = _(WARRANT_COMMENT['valid'])
|
||||
date_inv_at_server = datetime.strptime(date_invoice,
|
||||
DEFAULT_SERVER_DATE_FORMAT)
|
||||
supplier = claim_line.product_id.seller_ids[0]
|
||||
waranty_duration = relativedelta(months=int(supplier.warranty_duration))
|
||||
if claim_line.claim_id.claim_type == 'supplier':
|
||||
if claim_line.prodlot_id :
|
||||
limit = (datetime.strptime(date_invoice, DEFAULT_SERVER_DATE_FORMAT) + relativedelta(months=int(claim_line.product_id.seller_ids[0].warranty_duration))).strftime(DEFAULT_SERVER_DATE_FORMAT) # TODO: To be implemented
|
||||
# TODO: To be implemented
|
||||
limit = (date_inv_at_server +
|
||||
waranty_duration).strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||
else :
|
||||
limit = (datetime.strptime(date_invoice, DEFAULT_SERVER_DATE_FORMAT) + relativedelta(months=int(claim_line.product_id.seller_ids[0].warranty_duration))).strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||
limit = (date_inv_at_server +
|
||||
waranty_duration).strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||
else :
|
||||
limit = (datetime.strptime(date_invoice, DEFAULT_SERVER_DATE_FORMAT) + relativedelta(months=int(claim_line.product_id.warranty))).strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||
waranty_duration = relativedelta(months=int(claim_line.product_id.warranty))
|
||||
limit = (date_inv_at_server +
|
||||
waranty_duration).strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||
if limit < claim_line.claim_id.date:
|
||||
warning = 'Expired'
|
||||
warning = _(WARRANT_COMMENT['expired'])
|
||||
self.write(cr,uid,ids,{
|
||||
'guarantee_limit' : limit,
|
||||
'warning' : warning,
|
||||
})
|
||||
else:
|
||||
raise osv.except_osv(_('Error !'), _('Cannot find any date for invoice ! Must be a validated invoice !'))
|
||||
raise osv.except_osv(_('Error !'),
|
||||
_('Cannot find any date for invoice ! Must be a validated invoice !'))
|
||||
return True
|
||||
|
||||
# Method to calculate warranty return address
|
||||
def set_warranty_return_address(self, cr, uid, ids, claim_line, context=None):
|
||||
def set_warranty_return_address(self, cr, uid, ids,
|
||||
claim_line, context=None):
|
||||
return_address = None
|
||||
warranty_type = 'company'
|
||||
seller = claim_line.product_id.seller_info_id
|
||||
claim_company = claim_line.claim_id.company_id
|
||||
if seller:
|
||||
return_partner = seller.warranty_return_partner
|
||||
if return_partner:
|
||||
@@ -151,61 +214,86 @@ class claim_line(orm.Model):
|
||||
#raise osv.except_osv(_('Error !'), _('Cannot find any warranty return partner for this product !'))
|
||||
else :
|
||||
warranty_type = 'company'
|
||||
if claim_line.claim_id.company_id.crm_return_address_id:
|
||||
return_address = [claim_line.claim_id.company_id.crm_return_address_id.id]
|
||||
if claim_company.crm_return_address_id:
|
||||
return_address = [claim_company.crm_return_address_id.id]
|
||||
else:
|
||||
return_address = [claim_line.claim_id.company_id.partner_id.address[0].id]
|
||||
return_address = [claim_company.partner_id.address[0].id]
|
||||
# return_address = self._get_default_company_address(cr, uid, claim_line.claim_id.company_id, context=context)
|
||||
#TODO fix me use default address
|
||||
# self.write(cr,uid,ids,{'warranty_return_partner':1,'warranty_type': 'company'})
|
||||
# return True
|
||||
#raise osv.except_osv(_('Error !'), _('Cannot find any supplier for this product !'))
|
||||
self.write(cr,uid,ids,{'warranty_return_partner':return_address,'warranty_type':warranty_type})
|
||||
self.write(cr, uid, ids,
|
||||
{'warranty_return_partner':return_address,
|
||||
'warranty_type':warranty_type})
|
||||
return True
|
||||
|
||||
# Method to calculate warranty limit and validity
|
||||
def set_warranty(self, cr, uid, ids, context=None):
|
||||
for claim_line in self.browse(cr, uid, ids, context=context):
|
||||
if claim_line.product_id and claim_line.invoice_line_id:
|
||||
self.set_warranty_limit(cr, uid, ids, claim_line, context)
|
||||
self.set_warranty_return_address(cr, uid, ids, claim_line, context)
|
||||
self.set_warranty_limit(cr, uid, ids,
|
||||
claim_line, context=context)
|
||||
self.set_warranty_return_address(cr, uid, ids,
|
||||
claim_line, context=context)
|
||||
else:
|
||||
raise osv.except_osv(_('Error !'), _('PLEASE SET PRODUCT & INVOICE!'))
|
||||
raise osv.except_osv(_('Error !'),
|
||||
_('PLEASE SET PRODUCT & INVOICE!'))
|
||||
return True
|
||||
|
||||
#TODO add the option to split the claim_line in order to manage the same product separately
|
||||
|
||||
#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'
|
||||
|
||||
_columns = {
|
||||
'number': fields.char('Number', size=128,readonly=True,states={'draft': [('readonly', False)]},required=True, help="Company internal claim unique number"),
|
||||
'claim_type': fields.selection([('customer','Customer'),
|
||||
('supplier','Supplier'),
|
||||
('other','Other')], 'Claim type', required=True, help="customer = from customer to company ; supplier = from company to supplier"),
|
||||
'claim_line_ids' : fields.one2many('claim.line', 'claim_id', 'Return lines'),
|
||||
# Aftersale outsourcing
|
||||
# 'in_supplier_picking_id': fields.many2one('stock.picking', 'Return To Supplier Picking', required=False, select=True),
|
||||
# 'out_supplier_picking_id': fields.many2one('stock.picking', 'Return From Supplier Picking', required=False, select=True),
|
||||
def _get_sequence_number(self, cr, uid, context=None):
|
||||
return obj.pool.get('ir.sequence').get(cr, uid, 'crm.claim')
|
||||
|
||||
# Financial management
|
||||
def _get_default_warehouse(self, cr, uid, context=None):
|
||||
company_id = self.pool.get('res.users').browse(cr, uid, uid,
|
||||
context=context).company_id.id
|
||||
wh_ids = self.pool.get('stock.warehouse').search(cr, uid,
|
||||
[('company_id','=',company_id)], context=context)
|
||||
if not wh_ids:
|
||||
raise osv.except_osv(_('Error!'),
|
||||
_('There is no warehouse for the current user\'s company!'))
|
||||
return wh_ids[0]
|
||||
|
||||
_columns = {
|
||||
'number': fields.char('Number', size=128, readonly=True,
|
||||
states={'draft': [('readonly', False)]},
|
||||
required=True,
|
||||
help="Company internal claim unique number"),
|
||||
'claim_type': fields.selection([('customer','Customer'),
|
||||
('supplier','Supplier'),
|
||||
('other','Other')],
|
||||
'Claim type',
|
||||
required=True,
|
||||
help="customer = from customer to company ; supplier = from "
|
||||
"company to supplier"),
|
||||
'claim_line_ids' : fields.one2many('claim.line', 'claim_id',
|
||||
'Return lines'),
|
||||
'planned_revenue': fields.float('Expected revenue'),
|
||||
'planned_cost': fields.float('Expected cost'),
|
||||
'real_revenue': fields.float('Real revenue'),
|
||||
'real_cost': fields.float('Real cost'),
|
||||
'invoice_ids': fields.one2many('account.invoice', 'claim_id', 'Refunds'),
|
||||
'picking_ids': fields.one2many('stock.picking', 'claim_id', 'RMA'),
|
||||
'invoice_id': fields.many2one('account.invoice', 'Invoice', help='Related invoice'),
|
||||
'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse', required=True),
|
||||
'invoice_id': fields.many2one('account.invoice', 'Invoice',
|
||||
help='Related original Cusotmer invoice'),
|
||||
'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse',
|
||||
required=True),
|
||||
}
|
||||
_defaults = {
|
||||
'number': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'crm.claim'),
|
||||
'claim_type': lambda *a: 'customer',
|
||||
'warehouse_id': lambda *a: 1,
|
||||
'number': _get_sequence_number,
|
||||
'claim_type': 'customer',
|
||||
'warehouse_id': _get_default_warehouse,
|
||||
}
|
||||
|
||||
def onchange_partner_address_id(self, cr, uid, ids, add, email=False, context=None):
|
||||
res = super(crm_claim, self).onchange_partner_address_id(cr, uid, ids, add, email=email)
|
||||
def onchange_partner_address_id(self, cr, uid, ids, add,
|
||||
email=False, context=None):
|
||||
res = super(crm_claim, self).onchange_partner_address_id(cr, uid, ids,
|
||||
add, email=email)
|
||||
if add:
|
||||
if not res['value']['email_from'] or not res['value']['partner_phone']:
|
||||
address = self.pool.get('res.partner').browse(cr, uid, add)
|
||||
@@ -218,10 +306,10 @@ class crm_claim(orm.Model):
|
||||
|
||||
def onchange_invoice_id(self, cr, uid, ids, invoice_id, context=None):
|
||||
invoice_line_obj = self.pool.get('account.invoice.line')
|
||||
invoice_line_ids = invoice_line_obj.search(cr, uid, [('invoice_id', '=', invoice_id)])
|
||||
invoice_line_ids = invoice_line_obj.search(cr, uid,
|
||||
[('invoice_id','=',invoice_id)])
|
||||
claim_lines = []
|
||||
for invoice_line in invoice_line_obj.browse(cr,uid,invoice_line_ids):
|
||||
# claim_line_obj = self.pool.get('claim.line')
|
||||
claim_lines.append({
|
||||
'name': invoice_line.name,
|
||||
'claim_origine' : "none",
|
||||
@@ -229,11 +317,7 @@ class crm_claim(orm.Model):
|
||||
'product_id' : invoice_line.product_id.id,
|
||||
'product_returned_quantity' : invoice_line.quantity,
|
||||
'unit_sale_price' : invoice_line.price_unit,
|
||||
# 'prodlot_id' : invoice_line.,
|
||||
'state' : 'draft',
|
||||
})
|
||||
# for line in claim_line_obj.browse(cr,uid,[line_id],context):
|
||||
# line.set_warranty()
|
||||
return {'value' : {'claim_line_ids' : claim_lines}}
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -20,13 +20,19 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import fields, osv
|
||||
from openerp.osv import fields, orm, osv
|
||||
|
||||
class res_company(osv.osv):
|
||||
|
||||
class res_company(orm.Model):
|
||||
|
||||
_inherit = "res.company"
|
||||
|
||||
_columns = {
|
||||
'crm_return_address_id': fields.many2one('res.partner', 'Crm return address', help="Default address where the customers has to send back the returned product in a crm claim. If empty the address is the company address"),
|
||||
'crm_return_address_id': fields.many2one('res.partner',
|
||||
'Crm return address',
|
||||
help="Default address where the customers has to send back the "
|
||||
"returned product in a crm claim. If empty the address is the "
|
||||
"company address"),
|
||||
}
|
||||
|
||||
res_company()
|
||||
|
||||
|
||||
@@ -19,10 +19,10 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
from openerp.osv import fields, orm, osv
|
||||
|
||||
from osv import fields, osv
|
||||
|
||||
class stock_picking(osv.osv):
|
||||
class stock_picking(orm.Model):
|
||||
|
||||
_inherit = "stock.picking"
|
||||
|
||||
@@ -36,11 +36,15 @@ class stock_picking(osv.osv):
|
||||
seq_obj_name = 'stock.picking.' + vals['type']
|
||||
else:
|
||||
seq_obj_name = self._name
|
||||
vals['name'] = self.pool.get('ir.sequence').get(cr, user, seq_obj_name)
|
||||
new_id = super(stock_picking, self).create(cr, user, vals, context)
|
||||
vals['name'] = self.pool.get('ir.sequence').get(cr, user,
|
||||
seq_obj_name,
|
||||
context=context)
|
||||
new_id = super(stock_picking, self).create(cr, user, vals,
|
||||
context=context)
|
||||
return new_id
|
||||
|
||||
class stock_picking_out(osv.osv):
|
||||
|
||||
class stock_picking_out(orm.Model):
|
||||
|
||||
_inherit = "stock.picking.out"
|
||||
|
||||
@@ -49,7 +53,7 @@ class stock_picking_out(osv.osv):
|
||||
}
|
||||
|
||||
|
||||
class stock_picking_out(osv.osv):
|
||||
class stock_picking_out(orm.Model):
|
||||
|
||||
_inherit = "stock.picking.in"
|
||||
|
||||
@@ -58,29 +62,35 @@ class stock_picking_out(osv.osv):
|
||||
}
|
||||
|
||||
|
||||
class stock_warehouse(osv.osv):
|
||||
class stock_warehouse(orm.Model):
|
||||
|
||||
_inherit = "stock.warehouse"
|
||||
|
||||
|
||||
_columns = {
|
||||
'lot_rma_id': fields.many2one('stock.location', 'Location RMA'),
|
||||
'lot_carrier_loss_id': fields.many2one('stock.location', 'Location Carrier Loss'),
|
||||
'lot_breakage_loss_id': fields.many2one('stock.location', 'Location Breakage Loss'),
|
||||
'lot_refurbish_id': fields.many2one('stock.location', 'Location Refurbish'),
|
||||
'lot_carrier_loss_id': fields.many2one('stock.location',
|
||||
'Location Carrier Loss'),
|
||||
'lot_breakage_loss_id': fields.many2one('stock.location',
|
||||
'Location Breakage Loss'),
|
||||
'lot_refurbish_id': fields.many2one('stock.location',
|
||||
'Location Refurbish'),
|
||||
}
|
||||
|
||||
#This part concern the case of a wrong picking out. We need to create a new stock_move in a micking already open.
|
||||
#In order to don't have to confirm the stock_move we override the create and confirm it at the creation only for this case
|
||||
|
||||
class stock_move(osv.osv):
|
||||
#This part concern the case of a wrong picking out. We need to create a new
|
||||
#stock_move in a micking already open.
|
||||
#In order to don't have to confirm the stock_move we override the create and
|
||||
#confirm it at the creation only for this case
|
||||
class stock_move(orm.Model):
|
||||
|
||||
_inherit = "stock.move"
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
move_id = super(stock_move, self).create(cr, uid, vals, context=context)
|
||||
if vals.get('picking_id'):
|
||||
picking = self.pool.get('stock.picking').browse(cr, uid, vals['picking_id'], context=context)
|
||||
picking = self.pool.get('stock.picking').browse(cr, uid,
|
||||
vals['picking_id'], context=context)
|
||||
if picking.claim_id and picking.type == u'in':
|
||||
move = self.write(cr, uid, move_id, {'state': 'confirmed'}, context=context)
|
||||
move = self.write(cr, uid, move_id, {'state': 'confirmed'},
|
||||
context=context)
|
||||
return move_id
|
||||
|
||||
@@ -20,8 +20,7 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import returned_lines_from_serial
|
||||
import get_empty_serial
|
||||
import claim_make_picking
|
||||
import account_invoice_refund
|
||||
import claim_make_picking_from_picking
|
||||
from . import returned_lines_from_serial
|
||||
from . import claim_make_picking
|
||||
from . import account_invoice_refund
|
||||
from . import claim_make_picking_from_picking
|
||||
|
||||
@@ -1,33 +1,36 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#########################################################################
|
||||
# #
|
||||
# crm_claim_rma for OpenERP #
|
||||
# Copyright (C) 2012 Akretion, #
|
||||
# Benoît GUILLOT <benoit.guillot@akretion.com> #
|
||||
#This program is free software: you can redistribute it and/or modify #
|
||||
#it under the terms of the GNU General Public License as published by #
|
||||
#the Free Software Foundation, either version 3 of the License, or #
|
||||
#(at your option) any later version. #
|
||||
# #
|
||||
#This program is distributed in the hope that it will be useful, #
|
||||
#but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
#GNU General Public License for more details. #
|
||||
# #
|
||||
#You should have received a copy of the GNU General Public License #
|
||||
#along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
||||
#########################################################################
|
||||
##############################################################################
|
||||
#
|
||||
# Copyright 2013 Camptocamp
|
||||
# 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
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
from openerp.osv import fields, orm
|
||||
|
||||
from osv import fields, osv
|
||||
|
||||
class account_invoice_refund(osv.osv_memory):
|
||||
class account_invoice_refund(orm.TransientModel):
|
||||
_inherit = "account.invoice.refund"
|
||||
|
||||
def compute_refund(self, cr, uid, ids, mode='refund', context=None):
|
||||
if context is None: context={}
|
||||
if context.get('invoice_ids'):
|
||||
context['active_ids'] = context.get('invoice_ids')
|
||||
return super(account_invoice_refund, self).compute_refund(cr, uid, ids, mode='refund', context=context)
|
||||
return super(account_invoice_refund, self).compute_refund(cr, uid, ids,
|
||||
mode='refund', context=context)
|
||||
|
||||
def _get_description(self, cr, uid, context=None):
|
||||
if context is None: context = {}
|
||||
@@ -38,9 +41,3 @@ class account_invoice_refund(osv.osv_memory):
|
||||
'description': _get_description,
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
account_invoice_refund()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -20,15 +20,14 @@
|
||||
#You should have received a copy of the GNU General Public License #
|
||||
#along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
||||
#########################################################################
|
||||
|
||||
from osv import fields, osv
|
||||
from openerp.osv import fields, orm
|
||||
import time
|
||||
from tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
|
||||
import netsvc
|
||||
from tools.translate import _
|
||||
|
||||
|
||||
class claim_make_picking(osv.osv_memory):
|
||||
class claim_make_picking(orm.TransientModel):
|
||||
_name='claim_make_picking.wizard'
|
||||
_description='Wizard to create pickings from claim lines'
|
||||
_columns = {
|
||||
|
||||
@@ -21,13 +21,13 @@
|
||||
#along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
||||
#########################################################################
|
||||
|
||||
from osv import fields, osv
|
||||
from openerp.osv import fields, orm
|
||||
import time
|
||||
from tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
|
||||
import netsvc
|
||||
|
||||
|
||||
class claim_make_picking_from_picking(osv.osv_memory):
|
||||
class claim_make_picking_from_picking(orm.TransientModel):
|
||||
_name='claim_make_picking_from_picking.wizard'
|
||||
_description='Wizard to create pickings from picking lines'
|
||||
_columns = {
|
||||
|
||||
@@ -19,11 +19,11 @@
|
||||
#You should have received a copy of the GNU General Public License #
|
||||
#along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
||||
#########################################################################
|
||||
|
||||
from osv import fields, osv
|
||||
from openerp.osv import fields, orm
|
||||
import pooler
|
||||
|
||||
class returned_lines_from_serial(osv.osv_memory):
|
||||
|
||||
class returned_lines_from_serial(orm.TransientModel):
|
||||
_name='returned_lines_from_serial.wizard'
|
||||
_description='Wizard to create product return lines from serial numbers'
|
||||
_columns = {
|
||||
|
||||
Reference in New Issue
Block a user