mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[11.0] MIG: RMA module
This commit is contained in:
committed by
ahenriquez
parent
f9c7b28af8
commit
ae0a75499a
65
rma/models/rma_order.py
Normal file → Executable file
65
rma/models/rma_order.py
Normal file → Executable file
@@ -3,7 +3,7 @@
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
@@ -20,18 +20,18 @@ class RmaOrder(models.Model):
|
||||
@api.multi
|
||||
def _compute_in_shipment_count(self):
|
||||
for rec in self:
|
||||
rec.in_shipment_count = len(rec.rma_line_ids.mapped(
|
||||
'move_ids').filtered(
|
||||
lambda m: m.location_dest_id.usage == 'internal').mapped(
|
||||
'picking_id'))
|
||||
rec.in_shipment_count = len(
|
||||
rec.rma_line_ids.mapped('move_ids').filtered(
|
||||
lambda m: m.location_dest_id.usage == 'internal').mapped(
|
||||
'picking_id'))
|
||||
|
||||
@api.multi
|
||||
def _compute_out_shipment_count(self):
|
||||
for rec in self:
|
||||
rec.out_shipment_count = len(rec.rma_line_ids.mapped(
|
||||
'move_ids').filtered(
|
||||
lambda m: m.location_id.usage == 'internal').mapped(
|
||||
'picking_id'))
|
||||
rec.out_shipment_count = len(
|
||||
rec.rma_line_ids.mapped('move_ids').filtered(
|
||||
lambda m: m.location_id.usage == 'internal').mapped(
|
||||
'picking_id'))
|
||||
|
||||
@api.multi
|
||||
def _compute_supplier_line_count(self):
|
||||
@@ -111,14 +111,16 @@ class RmaOrder(models.Model):
|
||||
if move.picking_id.location_id == suppliers:
|
||||
picking_ids.append(move.picking_id.id)
|
||||
shipments = list(set(picking_ids))
|
||||
if not shipments:
|
||||
raise ValidationError(_("No shipments found!"))
|
||||
# choose the view_mode accordingly
|
||||
if len(shipments) != 1:
|
||||
result['domain'] = "[('id', 'in', " + \
|
||||
str(shipments) + ")]"
|
||||
elif len(shipments) == 1:
|
||||
res = self.env.ref('stock.view_picking_form', False)
|
||||
result['views'] = [(res and res.id or False, 'form')]
|
||||
result['res_id'] = shipments[0]
|
||||
if shipments:
|
||||
if len(shipments) > 1:
|
||||
result['domain'] = [('id', 'in', shipments)]
|
||||
else:
|
||||
res = self.env.ref('stock.view_picking_form', False)
|
||||
result['views'] = [(res and res.id or False, 'form')]
|
||||
result['res_id'] = shipments[0]
|
||||
return result
|
||||
|
||||
@api.multi
|
||||
@@ -138,11 +140,12 @@ class RmaOrder(models.Model):
|
||||
if move.picking_id.location_id != suppliers:
|
||||
picking_ids.append(move.picking_id.id)
|
||||
shipments = list(set(picking_ids))
|
||||
if not shipments:
|
||||
raise ValidationError(_("No deliveries found!"))
|
||||
# choose the view_mode accordingly
|
||||
if len(shipments) != 1:
|
||||
result['domain'] = "[('id', 'in', " + \
|
||||
str(shipments) + ")]"
|
||||
elif len(shipments) == 1:
|
||||
if len(shipments) > 1:
|
||||
result['domain'] = [('id', 'in', shipments)]
|
||||
else:
|
||||
res = self.env.ref('stock.view_picking_form', False)
|
||||
result['views'] = [(res and res.id or False, 'form')]
|
||||
result['res_id'] = shipments[0]
|
||||
@@ -159,20 +162,21 @@ class RmaOrder(models.Model):
|
||||
def action_view_lines(self):
|
||||
if self.type == 'customer':
|
||||
action = self.env.ref('rma.action_rma_customer_lines')
|
||||
res = self.env.ref('rma.view_rma_line_form', False)
|
||||
else:
|
||||
action = self.env.ref('rma.action_rma_supplier_lines')
|
||||
res = self.env.ref('rma.view_rma_line_supplier_form', False)
|
||||
result = action.read()[0]
|
||||
lines = self._get_valid_lines()
|
||||
if not lines:
|
||||
raise ValidationError(_("No rma %s lines found!") % self.type)
|
||||
# choose the view_mode accordingly
|
||||
if len(lines) != 1:
|
||||
if len(lines.ids) > 1:
|
||||
result['domain'] = [('id', 'in', lines.ids)]
|
||||
elif len(lines) == 1:
|
||||
if self.type == 'customer':
|
||||
res = self.env.ref('rma.view_rma_line_form', False)
|
||||
else:
|
||||
res = self.env.ref('rma.view_rma_line_supplier_form', False)
|
||||
else:
|
||||
result['views'] = [(res and res.id or False, 'form')]
|
||||
result['res_id'] = lines.id
|
||||
result['context'] = {}
|
||||
return result
|
||||
|
||||
@api.multi
|
||||
@@ -182,11 +186,12 @@ class RmaOrder(models.Model):
|
||||
lines = self.rma_line_ids
|
||||
for line_id in lines:
|
||||
related_lines = [line.id for line in line_id.supplier_rma_line_ids]
|
||||
if not related_lines:
|
||||
raise ValidationError(_("No rma supplier lines found!"))
|
||||
# choose the view_mode accordingly
|
||||
if len(related_lines) != 1:
|
||||
result['domain'] = "[('id', 'in', " + \
|
||||
str(related_lines) + ")]"
|
||||
elif len(related_lines) == 1:
|
||||
if len(related_lines) > 1:
|
||||
result['domain'] = [('id', 'in', related_lines)]
|
||||
else:
|
||||
res = self.env.ref('rma.view_rma_line_supplier_form', False)
|
||||
result['views'] = [(res and res.id or False, 'form')]
|
||||
result['res_id'] = related_lines[0]
|
||||
|
||||
Reference in New Issue
Block a user