[9.0] rma: remove rma.rule and add that setting to product.category

This commit is contained in:
lreficent
2017-08-02 14:04:18 +02:00
committed by AaronHForgeFlow
parent 58da75554a
commit b0c14c7b0a
13 changed files with 59 additions and 140 deletions

View File

@@ -5,9 +5,8 @@
from . import rma_order
from . import rma_order_line
from . import rma_operation
from . import rma_rule
from . import stock
from . import stock_warehouse
from . import product
from . import product_category
from . import procurement
from . import res_company

View File

@@ -16,7 +16,7 @@ class ProcurementOrder(models.Model):
if procurement.rma_line_id:
line = procurement.rma_line_id
res['rma_line_id'] = line.id
if line.delivery_address_id and line.delivery_address_id.id:
if line.delivery_address_id:
res['partner_id'] = line.delivery_address_id.id
elif line.invoice_line_id.invoice_id.partner_id:
res['partner_id'] = line.invoice_id.partner_id.id

View File

@@ -5,15 +5,10 @@
from openerp import fields, models
class ProductCategory(models.Model):
_inherit = 'product.category'
rma_operation_id = fields.Many2one(
comodel_name="rma.operation", string="RMA Operation")
class ProductTemplate(models.Model):
_inherit = 'product.template'
rma_operation_id = fields.Many2one(
comodel_name="rma.operation", string="RMA Operation")
rma_approval_policy = fields.Selection(
related="categ_id.rma_approval_policy", readonly=True)

View File

@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from openerp import fields, models
class ProductCategory(models.Model):
_inherit = "product.category"
rma_approval_policy = fields.Selection(
selection=[('one_step', 'One step'), ('two_step', 'Two steps')],
string="RMA Approval Policy", required=True, default='one_step',
help="Options: \n "
"* One step: Always auto-approve RMAs that only contain "
"products within categories with this policy.\n"
"* Two steps: A RMA containing a product within a category with "
"this policy will request the RMA manager approval.")
rma_operation_id = fields.Many2one(
comodel_name="rma.operation", string="RMA Operation")

View File

@@ -1,11 +0,0 @@
# -*- coding: utf-8 -*-
# © 2017 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from openerp import models, fields
class ResCompany(models.Model):
_inherit = 'res.company'
rma_rule_id = fields.Many2one('rma.rule', 'Default RMA Approval Policy')

View File

@@ -14,12 +14,6 @@ class RmaOrder(models.Model):
_name = "rma.order"
_inherit = ['mail.thread']
@api.model
def _compute_rule_id(self):
if self.company_id and self.company_id.id:
if self.company_id.rma_rule_id and self.company_id.rma_rule_id.id:
self.rule_id = self.company_id.rma_rule_id
@api.model
def _get_default_type(self):
if 'supplier' in self.env.context:
@@ -79,8 +73,6 @@ class RmaOrder(models.Model):
requested_by = fields.Many2one('res.users', 'Requested by',
track_visibility='onchange',
default=lambda self: self.env.user)
rule_id = fields.Many2one('rma.rule', string='Approval Criteria',
compute=_compute_rule_id)
rma_line_ids = fields.One2many('rma.order.line', 'rma_id',
string='RMA lines')
in_shipment_count = fields.Integer(compute=_compute_in_shipment_count,
@@ -163,12 +155,12 @@ class RmaOrder(models.Model):
@api.multi
def action_rma_to_approve(self):
self.write({'state': 'to_approve'})
for rec in self:
rec.state = 'to_approve'
if rec.rule_id and rec.rule_id.id:
if rec.rule_id.approval_policy == 'always':
rec.assigned_to = self.env.uid
rec.action_rma_approve()
pols = rec.mapped('rma_line_ids.product_id.rma_approval_policy')
if not any(x != 'one_step' for x in pols):
rec.write({'assigned_to': self.env.uid})
rec.action_rma_approve()
return True
@api.multi
@@ -180,8 +172,7 @@ class RmaOrder(models.Model):
@api.multi
def action_rma_approve(self):
# pass the supplier address in case this is a customer RMA
for rec in self:
rec.state = 'approved'
self.write({'state': 'approved'})
return True
@api.multi

View File

@@ -1,16 +0,0 @@
# -*- coding: utf-8 -*-
# © 2017 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from openerp import _, api, fields, models
class RmaRule(models.Model):
_name = 'rma.rule'
_description = 'RMA Approval Conditions'
name = fields.Char('Description', required=True)
code = fields.Char('Code', required=True)
approval_policy = fields.Selection([
('always', 'Always')], string="Approval Policy",
required=True, default='always')