diff --git a/crm_claim_rma/account_invoice.py b/crm_claim_rma/account_invoice.py
index 4f771d93..c52bd674 100644
--- a/crm_claim_rma/account_invoice.py
+++ b/crm_claim_rma/account_invoice.py
@@ -22,19 +22,21 @@
#
##############################################################################
-from openerp.models import Model, api, _
-from openerp import fields
+from openerp import models, fields, api, exceptions
+from openerp.tools.translate import _
-class AccountInvoice(Model):
+class AccountInvoice(models.Model):
_inherit = "account.invoice"
claim_id = fields.Many2one('crm.claim', string='Claim')
@api.model
def _refund_cleanup_lines(self, lines):
- """ Override when from claim to update the quantity and link to the
- claim line."""
+ """
+ Override when from claim to update the quantity and link to the
+ claim line.
+ """
new_lines = []
inv_line_obj = self.env['account.invoice.line']
claim_line_obj = self.env['claim.line']
@@ -67,7 +69,7 @@ class AccountInvoice(Model):
if not new_lines:
# TODO use custom states to show button of this wizard or
# not instead of raise an error
- raise Warning(
+ raise exceptions.Warning(
_('A refund has already been created for this claim !'))
return [(0, 0, l) for l in new_lines]
@@ -79,12 +81,12 @@ class AccountInvoice(Model):
journal_id=journal_id)
if self.env.context.get('claim_id'):
- result['claim_id'] = self.env.context.get('claim_id')
+ result['claim_id'] = self.env.context['claim_id']
return result
-class AccountInvoiceLine(Model):
+class AccountInvoiceLine(models.Model):
_inherit = "account.invoice.line"
@api.model
diff --git a/crm_claim_rma/crm_claim_rma.py b/crm_claim_rma/crm_claim_rma.py
index 2840bcf4..29542272 100644
--- a/crm_claim_rma/crm_claim_rma.py
+++ b/crm_claim_rma/crm_claim_rma.py
@@ -21,30 +21,28 @@
# along with this program. If not, see .
#
##############################################################################
-
-from openerp.models import Model, api, _
-from openerp import fields
-from openerp.tools import (DEFAULT_SERVER_DATE_FORMAT,
- DEFAULT_SERVER_DATETIME_FORMAT)
-from openerp.exceptions import except_orm, Warning
-
import math
import calendar
from datetime import datetime
from dateutil.relativedelta import relativedelta
+from openerp.models import models, fields, api, exceptions
+from openerp.tools.misc import (DEFAULT_SERVER_DATE_FORMAT,
+ DEFAULT_SERVER_DATETIME_FORMAT)
+from openerp.tools.translate import _
-class InvoiceNoDate(Exception):
+
+class InvoiceNoDate(exceptions.Exception):
""" Raised when a warranty cannot be computed for a claim line
because the invoice has no date. """
-class ProductNoSupplier(Exception):
+class ProductNoSupplier(exceptions.Exception):
""" Raised when a warranty cannot be computed for a claim line
because the product has no supplier. """
-class SubstateSubstate(Model):
+class SubstateSubstate(models.Model):
""" To precise a state (state=refused; substates= reason 1, 2,...) """
_name = "substate.substate"
_description = "substate that precise a given state"
@@ -55,7 +53,7 @@ class SubstateSubstate(Model):
help="To give more information about the sub state")
-class ClaimLine(Model):
+class ClaimLine(models.Model):
"""
Class to handle a product return line (corresponding to one invoice line)
"""
@@ -203,7 +201,6 @@ class ClaimLine(Model):
``relative_delta(months=...)`` only accepts integers.
We have to extract the decimal part, and then, extend the delta with
days.
-
"""
decimal_part, months = math.modf(warranty_duration)
months = int(months)
@@ -259,11 +256,11 @@ class ClaimLine(Model):
values = self._warranty_limit_values(invoice, claim_type, product,
claim_date)
except InvoiceNoDate:
- raise Warning(
+ raise exceptions.Warning(
_('Error'), _('Cannot find any date for invoice. '
'Must be a validated invoice.'))
except ProductNoSupplier:
- raise Warning(
+ raise exceptions.Warning(
_('Error'), _('The product has no supplier configured.'))
self.write(values)
@@ -391,7 +388,7 @@ class ClaimLine(Model):
""" Calculate warranty limit and address """
for claim_line in self:
if not (claim_line.product_id and claim_line.invoice_line_id):
- raise Warning(
+ raise exceptions.Warning(
_('Error'), _('Please set product and invoice.'))
claim_line.set_warranty_limit()
claim_line.set_warranty_return_address()
@@ -399,7 +396,7 @@ class ClaimLine(Model):
# TODO add the option to split the claim_line in order to manage the same
# product separately
-class CrmClaim(Model):
+class CrmClaim(models.Model):
_inherit = 'crm.claim'
def _get_default_warehouse(self):
@@ -407,7 +404,7 @@ class CrmClaim(Model):
wh_obj = self.env['stock.warehouse']
wh = wh_obj.search([('company_id', '=', company_id)], limit=1)
if not wh:
- raise Warning(
+ raise exceptions.Warning(
_('There is no warehouse for the current user\'s company.'))
return wh
@@ -531,8 +528,7 @@ class CrmClaim(Model):
@api.model
def message_get_suggested_recipients(self):
- recipients = super(CrmClaim, self
- ).message_get_suggested_recipients()
+ recipients = super(CrmClaim, self).message_get_suggested_recipients()
try:
for claim in self:
if claim.partner_id:
@@ -543,7 +539,7 @@ class CrmClaim(Model):
self._message_add_suggested_recipient(
recipients, claim,
email=claim.email_from, reason=_('Customer Email'))
- except except_orm:
+ except exceptions.AccessError:
# no read access rights -> just ignore suggested recipients
# because this imply modifying followers
pass
diff --git a/crm_claim_rma/stock.py b/crm_claim_rma/stock.py
index 7d2a52b3..4f87dd10 100644
--- a/crm_claim_rma/stock.py
+++ b/crm_claim_rma/stock.py
@@ -22,14 +22,13 @@
#
##############################################################################
-from openerp.models import Model, api
-from openerp.fields import Many2one
+from openerp import models, fields, api
-class StockPicking(Model):
+class StockPicking(models.Model):
_inherit = "stock.picking"
- claim_id = Many2one('crm.claim', string='Claim')
+ claim_id = fields.Many2one('crm.claim', string='Claim')
@api.model
def create(self, vals):
@@ -42,15 +41,17 @@ class StockPicking(Model):
return picking
-# This part concern the case of a wrong picking out. We need to create a new
-# stock_move in a picking 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 StockMove(Model):
+class StockMove(models.Model):
_inherit = "stock.move"
@api.model
def create(self, vals):
+ """
+ In case of a wrong picking out, We need to create a new stock_move in a
+ picking already open.
+ To avoid having to confirm the stock_move, we override the create and
+ confirm it at the creation only for this case.
+ """
move = super(StockMove, self).create(vals)
if vals.get('picking_id'):
picking_obj = self.env['stock.picking']
diff --git a/crm_claim_rma/wizard/account_invoice_refund.py b/crm_claim_rma/wizard/account_invoice_refund.py
index 95ee91ae..a512f451 100644
--- a/crm_claim_rma/wizard/account_invoice_refund.py
+++ b/crm_claim_rma/wizard/account_invoice_refund.py
@@ -22,11 +22,10 @@
#
##############################################################################
-from openerp.models import api, TransientModel
-from openerp.fields import Char
+from openerp import models, fields, api
-class AccountInvoiceRefund(TransientModel):
+class AccountInvoiceRefund(models.TransientModel):
_inherit = "account.invoice.refund"
def _get_description(self):
@@ -37,7 +36,7 @@ class AccountInvoiceRefund(TransientModel):
description = context.get('description') or ''
return description
- description = Char(default=_get_description)
+ description = fields.Char(default=_get_description)
@api.one
def compute_refund(self, mode='refund'):
diff --git a/crm_claim_rma/wizard/claim_make_picking.py b/crm_claim_rma/wizard/claim_make_picking.py
index fa1bf9f4..b8a3fedc 100644
--- a/crm_claim_rma/wizard/claim_make_picking.py
+++ b/crm_claim_rma/wizard/claim_make_picking.py
@@ -21,23 +21,18 @@
# along with this program. If not, see .
#
##############################################################################
-
-from openerp.models import api, TransientModel, _
-from openerp.fields import Many2many, Many2one
-from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
-from openerp.exceptions import Warning
-from openerp import workflow
-from openerp import workflow
-
import time
+from openerp import models, fields, exceptions, api, workflow, _
+from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
-class ClaimMakePicking(TransientModel):
+
+class ClaimMakePicking(models.TransientModel):
_name = 'claim_make_picking.wizard'
_description = 'Wizard to create pickings from claim lines'
- # Get default source location
def _get_source_loc(self):
+ """Get default source location"""
loc_id = False
context = self.env.context
if context is None:
@@ -57,8 +52,10 @@ class ClaimMakePicking(TransientModel):
return loc_id
def _get_common_dest_location_from_line(self, line_ids):
- """Return the ID of the common location between all lines. If no common
- destination was found, return False"""
+ """
+ Return the ID of the common location between all lines. If no common
+ destination was found, return False
+ """
loc_id = False
line_obj = self.env['claim.line']
line_location = []
@@ -75,9 +72,11 @@ class ClaimMakePicking(TransientModel):
# Get default destination location
def _get_dest_loc(self):
"""Return the location_id to use as destination.
+
If it's an outoing shippment: take the customer stock property
If it's an incoming shippment take the location_dest_id common to all
- lines, or if different, return None."""
+ lines, or if different, return None.
+ """
context = self.env.context
if context is None:
context = {}
@@ -116,21 +115,21 @@ class ClaimMakePicking(TransientModel):
good_lines.append(line.id)
if not good_lines:
- raise Warning(
+ raise exceptions.Warning(
_('Error'),
_('A picking has already been created for this claim.'))
return good_lines
- claim_line_source_location = Many2one(
+ claim_line_source_location = fields.Many2one(
'stock.location', string='Source Location', required=True,
default=_get_source_loc,
help="Location where the returned products are from.")
- claim_line_dest_location = Many2one(
+ claim_line_dest_location = fields.Many2one(
'stock.location', string='Dest. Location', required=True,
default=_get_dest_loc,
help="Location where the system will stock the returned products.")
- claim_line_ids = Many2many(
+ claim_line_ids = fields.Many2many(
'claim.line',
'claim_line_picking',
'claim_picking_id',
@@ -138,8 +137,10 @@ class ClaimMakePicking(TransientModel):
string='Claim lines', default=_get_claim_lines)
def _get_common_partner_from_line(self, line_ids):
- """Return the ID of the common partner between all lines. If no common
- partner was found, return False"""
+ """
+ Return the ID of the common partner between all lines. If no common
+ partner was found, return False
+ """
partner_id = False
line_obj = self.env['claim.line']
line_partner = []
@@ -212,7 +213,7 @@ class ClaimMakePicking(TransientModel):
claim_lines.ids)
if not common_dest_partner_id:
- raise Warning(
+ raise exceptions.Warning(
_('Error'),
_('A product return cannot be created for various '
'destination addresses, please choose line with a '
@@ -221,20 +222,20 @@ class ClaimMakePicking(TransientModel):
partner_id = common_dest_partner_id
# create picking
- picking = picking_obj.create(
- {'origin': claim.code,
- 'picking_type_id': picking_type_id,
- 'move_type': 'one', # direct
- 'state': 'draft',
- 'date': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
- 'partner_id': partner_id,
- 'invoice_state': "none",
- 'company_id': claim.company_id.id,
- 'location_id': self.claim_line_source_location.id,
- 'location_dest_id': self.claim_line_dest_location.id,
- 'note': note,
- 'claim_id': claim.id,
- })
+ picking = picking_obj.create({
+ 'origin': claim.code,
+ 'picking_type_id': picking_type_id,
+ 'move_type': 'one', # direct
+ 'state': 'draft',
+ 'date': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
+ 'partner_id': partner_id,
+ 'invoice_state': "none",
+ 'company_id': claim.company_id.id,
+ 'location_id': self.claim_line_source_location.id,
+ 'location_dest_id': self.claim_line_dest_location.id,
+ 'note': note,
+ 'claim_id': claim.id,
+ })
# Create picking lines
fmt = DEFAULT_SERVER_DATETIME_FORMAT