mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
Merge pull request #111 from Eficent/10.0-fix-rma_analytic
[10.0][FIX]rma_analytic. Propagate analytic to other models
This commit is contained in:
@@ -9,6 +9,7 @@ python:
|
||||
- "2.7"
|
||||
|
||||
addons:
|
||||
postgresql: "9.6"
|
||||
apt:
|
||||
packages:
|
||||
- expect-dev # provides unbuffer utility
|
||||
|
||||
@@ -88,10 +88,10 @@ class TestAccountMoveLineRmaOrderLine(common.SavepointCase):
|
||||
return user.id
|
||||
|
||||
@classmethod
|
||||
def _create_account_type(cls, name, type):
|
||||
def _create_account_type(cls, name, atype):
|
||||
acc_type = cls.acc_type_model.create({
|
||||
'name': name,
|
||||
'type': type
|
||||
'type': atype
|
||||
})
|
||||
return acc_type
|
||||
|
||||
@@ -178,8 +178,8 @@ class TestAccountMoveLineRmaOrderLine(common.SavepointCase):
|
||||
data = wizard._prepare_rma_line_from_stock_move(move)
|
||||
wizard.add_lines()
|
||||
|
||||
for operation in move.product_id.rma_customer_operation_id:
|
||||
operation.in_route_id = False
|
||||
if move.product_id.rma_customer_operation_id:
|
||||
move.product_id.rma_customer_operation_id.in_route_id = False
|
||||
move.product_id.categ_id.rma_customer_operation_id = False
|
||||
move.product_id.rma_customer_operation_id = False
|
||||
wizard._prepare_rma_line_from_stock_move(move)
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
# © 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# 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 import api, fields, models
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
@@ -69,16 +68,6 @@ class RmaOrder(models.Model):
|
||||
required=True, default=lambda self:
|
||||
self.env.user.company_id)
|
||||
|
||||
@api.constrains("partner_id", "rma_line_ids")
|
||||
def _check_partner_id(self):
|
||||
if self.rma_line_ids and self.partner_id != self.mapped(
|
||||
"rma_line_ids.partner_id"):
|
||||
raise UserError(_(
|
||||
"Group partner and RMA's partner must be the same."))
|
||||
if len(self.mapped("rma_line_ids.partner_id")) > 1:
|
||||
raise UserError(_(
|
||||
"All grouped RMA's should have same partner."))
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
if (self.env.context.get('supplier') or
|
||||
|
||||
@@ -401,8 +401,10 @@ class RmaOrderLine(models.Model):
|
||||
string="Under Warranty?",
|
||||
readonly=True, states={'draft': [('readonly', False)]},
|
||||
)
|
||||
create_date = fields.Datetime(string='Creation Date', readonly=True, index=True,
|
||||
create_date = fields.Datetime(string='Creation Date', readonly=True,
|
||||
index=True,
|
||||
help="Date on which RMA order is created.")
|
||||
|
||||
@api.multi
|
||||
def _prepare_rma_line_from_stock_move(self, sm, lot=False):
|
||||
if not self.type:
|
||||
@@ -674,3 +676,9 @@ class RmaOrderLine(models.Model):
|
||||
result['views'] = [(res and res.id or False, 'form')]
|
||||
result['res_id'] = rma_lines.id
|
||||
return result
|
||||
|
||||
@api.constrains("partner_id", "rma_id")
|
||||
def _check_partner_id(self):
|
||||
if self.rma_id and self.partner_id != self.rma_id.partner_id:
|
||||
raise ValidationError(_(
|
||||
"Group partner and RMA's partner must be the same."))
|
||||
|
||||
@@ -58,8 +58,8 @@ class StockWarehouse(models.Model):
|
||||
def _rma_types_available(self):
|
||||
self.ensure_one()
|
||||
rma_types = self._get_rma_types()
|
||||
for type in rma_types:
|
||||
if not type:
|
||||
for rtype in rma_types:
|
||||
if not rtype:
|
||||
return False
|
||||
return True
|
||||
|
||||
@@ -80,16 +80,16 @@ class StockWarehouse(models.Model):
|
||||
if not wh._rma_types_available():
|
||||
wh._create_rma_picking_types()
|
||||
else:
|
||||
for type in wh._get_rma_types():
|
||||
if type:
|
||||
type.active = True
|
||||
for rtype in wh._get_rma_types():
|
||||
if rtype:
|
||||
rtype.active = True
|
||||
# RMA rules:
|
||||
wh._create_or_update_rma_pull()
|
||||
else:
|
||||
for wh in self:
|
||||
for type in wh._get_rma_types():
|
||||
if type:
|
||||
type.active = False
|
||||
for rtype in wh._get_rma_types():
|
||||
if rtype:
|
||||
rtype.active = False
|
||||
# Unlink rules:
|
||||
self.mapped('rma_customer_in_pull_id').unlink()
|
||||
self.mapped('rma_customer_out_pull_id').unlink()
|
||||
|
||||
@@ -75,12 +75,12 @@ class TestRma(common.SavepointCase):
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def _create_rma_from_move(cls, products2move, type, partner, dropship,
|
||||
def _create_rma_from_move(cls, products2move, rtype, partner, dropship,
|
||||
supplier_address_id=None):
|
||||
picking_in = cls._create_picking(partner)
|
||||
|
||||
moves = []
|
||||
if type == 'customer':
|
||||
if rtype == 'customer':
|
||||
for item in products2move:
|
||||
move_values = cls._prepare_move(
|
||||
item[0], item[1], cls.stock_location,
|
||||
@@ -96,12 +96,12 @@ class TestRma(common.SavepointCase):
|
||||
rma_id = cls.rma.create(
|
||||
{
|
||||
'reference': '0001',
|
||||
'type': type,
|
||||
'type': rtype,
|
||||
'partner_id': partner.id,
|
||||
'company_id': cls.env.ref('base.main_company').id
|
||||
})
|
||||
for move in moves:
|
||||
if type == 'customer':
|
||||
if rtype == 'customer':
|
||||
wizard = cls.rma_add_stock_move.with_context(
|
||||
{'stock_move_id': move.id, 'customer': True,
|
||||
'active_ids': rma_id.id,
|
||||
@@ -111,8 +111,9 @@ class TestRma(common.SavepointCase):
|
||||
data = wizard._prepare_rma_line_from_stock_move(move)
|
||||
wizard.add_lines()
|
||||
|
||||
for operation in move.product_id.rma_customer_operation_id:
|
||||
operation.in_route_id = False
|
||||
if move.product_id.rma_customer_operation_id:
|
||||
move.product_id.rma_customer_operation_id.in_route_id = \
|
||||
False
|
||||
move.product_id.categ_id.rma_customer_operation_id = False
|
||||
move.product_id.rma_customer_operation_id = False
|
||||
wizard._prepare_rma_line_from_stock_move(move)
|
||||
@@ -124,7 +125,7 @@ class TestRma(common.SavepointCase):
|
||||
'active_model': 'rma.order',
|
||||
}
|
||||
).create({})
|
||||
data = wizard._prepare_rma_line_from_stock_move(move)
|
||||
wizard._prepare_rma_line_from_stock_move(move)
|
||||
wizard.add_lines()
|
||||
|
||||
wizard = cls.rma_add_stock_move.with_context(
|
||||
@@ -142,8 +143,9 @@ class TestRma(common.SavepointCase):
|
||||
}
|
||||
).create({})
|
||||
data = wizard._prepare_rma_line_from_stock_move(move)
|
||||
for operation in move.product_id.rma_customer_operation_id:
|
||||
operation.in_route_id = False
|
||||
if move.product_id.rma_customer_operation_id:
|
||||
move.product_id.rma_customer_operation_id.in_route_id = \
|
||||
False
|
||||
move.product_id.rma_customer_operation_id = False
|
||||
wizard.add_lines()
|
||||
|
||||
@@ -192,23 +194,23 @@ class TestRma(common.SavepointCase):
|
||||
up_wiz.change_product_qty()
|
||||
return True
|
||||
|
||||
def test_01_rma_order_line(cls):
|
||||
picking_in = cls._create_picking(cls.env.ref('base.res_partner_2'))
|
||||
def test_01_rma_order_line(self):
|
||||
picking_in = self._create_picking(self.env.ref('base.res_partner_2'))
|
||||
moves_1 = []
|
||||
move_values = cls._prepare_move(cls.product_1, 3,
|
||||
cls.stock_location,
|
||||
cls.customer_location, picking_in)
|
||||
moves_1.append(cls.env['stock.move'].create(move_values))
|
||||
wizard_1 = cls.rma_add_stock_move.with_context(
|
||||
move_values = self._prepare_move(self.product_1, 3,
|
||||
self.stock_location,
|
||||
self.customer_location, picking_in)
|
||||
moves_1.append(self.env['stock.move'].create(move_values))
|
||||
wizard_1 = self.rma_add_stock_move.with_context(
|
||||
{'supplier': True,
|
||||
'stock_move_id': [(6, 0, [m.id for m in moves_1])],
|
||||
'active_ids': cls.rma_customer_id.id,
|
||||
'active_ids': self.rma_customer_id.id,
|
||||
'active_model': 'rma.order',
|
||||
}
|
||||
).create({'move_ids': [(6, 0, [m.id for m in moves_1])]})
|
||||
wizard_1.add_lines()
|
||||
|
||||
for line in cls.rma_customer_id.rma_line_ids:
|
||||
for line in self.rma_customer_id.rma_line_ids:
|
||||
line.with_context({'default_rma_id': line.rma_id.id
|
||||
})._default_warehouse_id()
|
||||
line._default_location_id()
|
||||
@@ -219,127 +221,127 @@ class TestRma(common.SavepointCase):
|
||||
line._compute_procurement_count()
|
||||
|
||||
data = {'reference_move_id': line.reference_move_id.id}
|
||||
new_line = cls.rma_line.new(data)
|
||||
new_line = self.rma_line.new(data)
|
||||
new_line._onchange_reference_move_id()
|
||||
|
||||
# check assert if call reference_move_id onchange
|
||||
cls.assertEquals(new_line.product_id,
|
||||
line.reference_move_id.product_id)
|
||||
cls.assertEquals(new_line.product_qty,
|
||||
line.reference_move_id.product_uom_qty)
|
||||
cls.assertEquals(new_line.location_id.location_id,
|
||||
line.reference_move_id.location_id)
|
||||
cls.assertEquals(new_line.origin,
|
||||
line.reference_move_id.picking_id.name)
|
||||
cls.assertEquals(new_line.delivery_address_id,
|
||||
line.reference_move_id.picking_partner_id)
|
||||
cls.assertEquals(new_line.qty_to_receive,
|
||||
line.reference_move_id.product_uom_qty)
|
||||
self.assertEquals(new_line.product_id,
|
||||
line.reference_move_id.product_id)
|
||||
self.assertEquals(new_line.product_qty,
|
||||
line.reference_move_id.product_uom_qty)
|
||||
self.assertEquals(new_line.location_id.location_id,
|
||||
line.reference_move_id.location_id)
|
||||
self.assertEquals(new_line.origin,
|
||||
line.reference_move_id.picking_id.name)
|
||||
self.assertEquals(new_line.delivery_address_id,
|
||||
line.reference_move_id.picking_partner_id)
|
||||
self.assertEquals(new_line.qty_to_receive,
|
||||
line.reference_move_id.product_uom_qty)
|
||||
|
||||
line.action_rma_to_approve()
|
||||
line.action_rma_draft()
|
||||
line.action_rma_done()
|
||||
|
||||
data = {'product_id': line.product_id.id}
|
||||
new_line = cls.rma_line.new(data)
|
||||
new_line = self.rma_line.new(data)
|
||||
new_line._onchange_product_id()
|
||||
|
||||
data = {'operation_id': line.operation_id.id}
|
||||
new_line = cls.rma_line.new(data)
|
||||
new_line = self.rma_line.new(data)
|
||||
new_line._onchange_operation_id()
|
||||
|
||||
# check assert if call operation_id onchange
|
||||
cls.assertEquals(new_line.operation_id.receipt_policy,
|
||||
line.receipt_policy)
|
||||
self.assertEquals(new_line.operation_id.receipt_policy,
|
||||
line.receipt_policy)
|
||||
|
||||
data = {'customer_to_supplier': line.customer_to_supplier}
|
||||
new_line = cls.rma_line.new(data)
|
||||
new_line = self.rma_line.new(data)
|
||||
new_line._onchange_receipt_policy()
|
||||
|
||||
data = {'lot_id': line.lot_id.id}
|
||||
new_line = cls.rma_line.new(data)
|
||||
new_line = self.rma_line.new(data)
|
||||
new_line._onchange_lot_id()
|
||||
|
||||
line.action_view_in_shipments()
|
||||
line.action_view_out_shipments()
|
||||
line.action_view_procurements()
|
||||
cls.rma_customer_id.action_view_supplier_lines()
|
||||
with cls.assertRaises(ValidationError):
|
||||
line.rma_id.partner_id = cls.partner_id.id
|
||||
cls.rma_customer_id.rma_line_ids[0].\
|
||||
partner_id = cls.partner_id.id
|
||||
cls.rma_customer_id.action_view_supplier_lines()
|
||||
self.rma_customer_id.action_view_supplier_lines()
|
||||
with self.assertRaises(ValidationError):
|
||||
line.rma_id.partner_id = self.partner_id.id
|
||||
self.rma_customer_id.rma_line_ids[0].\
|
||||
partner_id = self.partner_id.id
|
||||
self.rma_customer_id.action_view_supplier_lines()
|
||||
|
||||
def test_02_customer_rma(cls):
|
||||
wizard = cls.rma_make_picking.with_context({
|
||||
'active_ids': cls.rma_customer_id.rma_line_ids.ids,
|
||||
def test_02_customer_rma(self):
|
||||
wizard = self.rma_make_picking.with_context({
|
||||
'active_ids': self.rma_customer_id.rma_line_ids.ids,
|
||||
'active_model': 'rma.order.line',
|
||||
'picking_type': 'incoming',
|
||||
'active_id': 1
|
||||
}).create({})
|
||||
# Before creating the picking:
|
||||
for line in cls.rma_customer_id.rma_line_ids:
|
||||
if line.product_id == cls.product_1:
|
||||
cls.assertEquals(line.qty_to_receive, 3.0)
|
||||
if line.product_id == cls.product_2:
|
||||
cls.assertEquals(line.qty_to_receive, 5.0)
|
||||
if line.product_id == cls.product_3:
|
||||
cls.assertEquals(line.qty_to_receive, 2.0)
|
||||
for line in self.rma_customer_id.rma_line_ids:
|
||||
if line.product_id == self.product_1:
|
||||
self.assertEquals(line.qty_to_receive, 3.0)
|
||||
if line.product_id == self.product_2:
|
||||
self.assertEquals(line.qty_to_receive, 5.0)
|
||||
if line.product_id == self.product_3:
|
||||
self.assertEquals(line.qty_to_receive, 2.0)
|
||||
|
||||
procurements = wizard._create_picking()
|
||||
group_ids = set([proc.group_id.id for proc in procurements if
|
||||
proc.group_id])
|
||||
domain = [('group_id', 'in', list(group_ids))]
|
||||
picking = cls.stockpicking.search(domain)
|
||||
cls.assertEquals(len(picking), 1,
|
||||
"Incorrect number of pickings created")
|
||||
picking = self.stockpicking.search(domain)
|
||||
self.assertEquals(len(picking), 1,
|
||||
"Incorrect number of pickings created")
|
||||
moves = picking.move_lines
|
||||
cls.assertEquals(len(moves), 3,
|
||||
"Incorrect number of moves created")
|
||||
self.assertEquals(len(moves), 3,
|
||||
"Incorrect number of moves created")
|
||||
# After creating the picking:
|
||||
for line in cls.rma_customer_id.rma_line_ids:
|
||||
for line in self.rma_customer_id.rma_line_ids:
|
||||
# common qtys for all products
|
||||
cls.assertEquals(line.qty_received, 0, "Wrong qty received")
|
||||
cls.assertEquals(line.qty_to_deliver, 0, "Wrong qty to deliver")
|
||||
cls.assertEquals(line.qty_outgoing, 0, "Wrong qty outgoing")
|
||||
cls.assertEquals(line.qty_delivered, 0, "Wrong qty delivered")
|
||||
self.assertEquals(line.qty_received, 0, "Wrong qty received")
|
||||
self.assertEquals(line.qty_to_deliver, 0, "Wrong qty to deliver")
|
||||
self.assertEquals(line.qty_outgoing, 0, "Wrong qty outgoing")
|
||||
self.assertEquals(line.qty_delivered, 0, "Wrong qty delivered")
|
||||
# product specific
|
||||
# qty to receive should not consider qty incoming
|
||||
if line.product_id == cls.product_1:
|
||||
cls.assertEquals(line.qty_incoming, 3.0)
|
||||
cls.assertEquals(line.qty_to_receive, 3.0,
|
||||
"Wrong qty to receive")
|
||||
if line.product_id == cls.product_2:
|
||||
cls.assertEquals(line.qty_incoming, 5.0)
|
||||
cls.assertEquals(line.qty_to_receive, 5.0,
|
||||
"Wrong qty to receive")
|
||||
if line.product_id == cls.product_3:
|
||||
cls.assertEquals(line.qty_to_receive, 2.0,
|
||||
"Wrong qty to receive")
|
||||
cls.assertEquals(line.qty_incoming, 2.0)
|
||||
if line.product_id == self.product_1:
|
||||
self.assertEquals(line.qty_incoming, 3.0)
|
||||
self.assertEquals(line.qty_to_receive, 3.0,
|
||||
"Wrong qty to receive")
|
||||
if line.product_id == self.product_2:
|
||||
self.assertEquals(line.qty_incoming, 5.0)
|
||||
self.assertEquals(line.qty_to_receive, 5.0,
|
||||
"Wrong qty to receive")
|
||||
if line.product_id == self.product_3:
|
||||
self.assertEquals(line.qty_to_receive, 2.0,
|
||||
"Wrong qty to receive")
|
||||
self.assertEquals(line.qty_incoming, 2.0)
|
||||
|
||||
# Validate the picking:
|
||||
picking.action_assign()
|
||||
picking.do_transfer()
|
||||
for line in cls.rma_customer_id.rma_line_ids:
|
||||
cls.assertEquals(line.qty_to_receive, 0, "Wrong qty to_receive")
|
||||
cls.assertEquals(line.qty_incoming, 0, "Wrong qty incoming")
|
||||
cls.assertEquals(line.qty_outgoing, 0, "Wrong qty outgoing")
|
||||
cls.assertEquals(line.qty_delivered, 0, "Wrong qty delivered")
|
||||
if line.product_id == cls.product_1:
|
||||
cls.assertEquals(line.qty_received, 3.0)
|
||||
cls.assertEquals(line.qty_to_deliver, 3.0)
|
||||
if line.product_id == cls.product_2:
|
||||
cls.assertEquals(line.qty_received, 5.0)
|
||||
cls.assertEquals(line.qty_to_deliver, 5.0)
|
||||
if line.product_id == cls.product_3:
|
||||
cls.assertEquals(line.qty_received, 2.0)
|
||||
cls.assertEquals(line.qty_to_deliver, 2.0)
|
||||
for line in self.rma_customer_id.rma_line_ids:
|
||||
self.assertEquals(line.qty_to_receive, 0, "Wrong qty to_receive")
|
||||
self.assertEquals(line.qty_incoming, 0, "Wrong qty incoming")
|
||||
self.assertEquals(line.qty_outgoing, 0, "Wrong qty outgoing")
|
||||
self.assertEquals(line.qty_delivered, 0, "Wrong qty delivered")
|
||||
if line.product_id == self.product_1:
|
||||
self.assertEquals(line.qty_received, 3.0)
|
||||
self.assertEquals(line.qty_to_deliver, 3.0)
|
||||
if line.product_id == self.product_2:
|
||||
self.assertEquals(line.qty_received, 5.0)
|
||||
self.assertEquals(line.qty_to_deliver, 5.0)
|
||||
if line.product_id == self.product_3:
|
||||
self.assertEquals(line.qty_received, 2.0)
|
||||
self.assertEquals(line.qty_to_deliver, 2.0)
|
||||
|
||||
# Create delivery:
|
||||
wizard = cls.rma_make_picking.with_context({
|
||||
wizard = self.rma_make_picking.with_context({
|
||||
'active_id': 1,
|
||||
'active_ids': cls.rma_customer_id.rma_line_ids.ids,
|
||||
'active_ids': self.rma_customer_id.rma_line_ids.ids,
|
||||
'active_model': 'rma.order.line',
|
||||
'picking_type': 'outgoing',
|
||||
}).create({})
|
||||
@@ -347,100 +349,100 @@ class TestRma(common.SavepointCase):
|
||||
group_ids = set([proc.group_id.id for proc in procurements if
|
||||
proc.group_id])
|
||||
domain = [('group_id', 'in', list(group_ids))]
|
||||
pickings = cls.stockpicking.search(domain)
|
||||
cls.assertEquals(len(pickings), 2,
|
||||
"Incorrect number of pickings created")
|
||||
pickings = self.stockpicking.search(domain)
|
||||
self.assertEquals(len(pickings), 2,
|
||||
"Incorrect number of pickings created")
|
||||
picking_out = pickings[1]
|
||||
moves = picking_out.move_lines
|
||||
cls.assertEquals(len(moves), 3,
|
||||
"Incorrect number of moves created")
|
||||
for line in cls.rma_customer_id.rma_line_ids:
|
||||
cls.assertEquals(line.qty_to_receive, 0, "Wrong qty to receive")
|
||||
cls.assertEquals(line.qty_incoming, 0, "Wrong qty incoming")
|
||||
cls.assertEquals(line.qty_delivered, 0, "Wrong qty delivered")
|
||||
if line.product_id == cls.product_1:
|
||||
cls.assertEquals(line.qty_to_deliver, 3.0,
|
||||
"Wrong qty to deliver")
|
||||
cls.assertEquals(line.qty_received, 3.0)
|
||||
cls.assertEquals(line.qty_outgoing, 3.0)
|
||||
if line.product_id == cls.product_2:
|
||||
cls.assertEquals(line.qty_to_deliver, 5.0,
|
||||
"Wrong qty to deliver")
|
||||
cls.assertEquals(line.qty_received, 5.0)
|
||||
cls.assertEquals(line.qty_outgoing, 5.0)
|
||||
if line.product_id == cls.product_3:
|
||||
cls.assertEquals(line.qty_to_deliver, 2.0,
|
||||
"Wrong qty to deliver")
|
||||
cls.assertEquals(line.qty_received, 2.0)
|
||||
cls.assertEquals(line.qty_outgoing, 2.0)
|
||||
self.assertEquals(len(moves), 3,
|
||||
"Incorrect number of moves created")
|
||||
for line in self.rma_customer_id.rma_line_ids:
|
||||
self.assertEquals(line.qty_to_receive, 0, "Wrong qty to receive")
|
||||
self.assertEquals(line.qty_incoming, 0, "Wrong qty incoming")
|
||||
self.assertEquals(line.qty_delivered, 0, "Wrong qty delivered")
|
||||
if line.product_id == self.product_1:
|
||||
self.assertEquals(line.qty_to_deliver, 3.0,
|
||||
"Wrong qty to deliver")
|
||||
self.assertEquals(line.qty_received, 3.0)
|
||||
self.assertEquals(line.qty_outgoing, 3.0)
|
||||
if line.product_id == self.product_2:
|
||||
self.assertEquals(line.qty_to_deliver, 5.0,
|
||||
"Wrong qty to deliver")
|
||||
self.assertEquals(line.qty_received, 5.0)
|
||||
self.assertEquals(line.qty_outgoing, 5.0)
|
||||
if line.product_id == self.product_3:
|
||||
self.assertEquals(line.qty_to_deliver, 2.0,
|
||||
"Wrong qty to deliver")
|
||||
self.assertEquals(line.qty_received, 2.0)
|
||||
self.assertEquals(line.qty_outgoing, 2.0)
|
||||
|
||||
# Validate delivery:
|
||||
picking_out.action_assign()
|
||||
picking_out.do_transfer()
|
||||
for line in cls.rma_customer_id.rma_line_ids:
|
||||
cls.assertEquals(line.qty_to_receive, 0, "Wrong qty to receive")
|
||||
cls.assertEquals(line.qty_incoming, 0, "Wrong qty incoming")
|
||||
cls.assertEquals(line.qty_to_deliver, 0, "Wrong qty to deliver")
|
||||
cls.assertEquals(line.qty_outgoing, 0, "Wrong qty outgoing")
|
||||
if line.product_id == cls.product_1:
|
||||
cls.assertEquals(line.qty_received, 3.0)
|
||||
cls.assertEquals(line.qty_delivered, 3.0)
|
||||
if line.product_id == cls.product_2:
|
||||
cls.assertEquals(line.qty_received, 5.0)
|
||||
cls.assertEquals(line.qty_delivered, 5.0)
|
||||
if line.product_id == cls.product_3:
|
||||
cls.assertEquals(line.qty_received, 2.0)
|
||||
cls.assertEquals(line.qty_delivered, 2.0)
|
||||
cls.line.action_rma_done()
|
||||
cls.assertEquals(cls.line.state, 'done', "Wrong State")
|
||||
for line in self.rma_customer_id.rma_line_ids:
|
||||
self.assertEquals(line.qty_to_receive, 0, "Wrong qty to receive")
|
||||
self.assertEquals(line.qty_incoming, 0, "Wrong qty incoming")
|
||||
self.assertEquals(line.qty_to_deliver, 0, "Wrong qty to deliver")
|
||||
self.assertEquals(line.qty_outgoing, 0, "Wrong qty outgoing")
|
||||
if line.product_id == self.product_1:
|
||||
self.assertEquals(line.qty_received, 3.0)
|
||||
self.assertEquals(line.qty_delivered, 3.0)
|
||||
if line.product_id == self.product_2:
|
||||
self.assertEquals(line.qty_received, 5.0)
|
||||
self.assertEquals(line.qty_delivered, 5.0)
|
||||
if line.product_id == self.product_3:
|
||||
self.assertEquals(line.qty_received, 2.0)
|
||||
self.assertEquals(line.qty_delivered, 2.0)
|
||||
self.line.action_rma_done()
|
||||
self.assertEquals(self.line.state, 'done', "Wrong State")
|
||||
|
||||
# Dummy call to action_view methods.
|
||||
cls.rma_customer_id.action_view_in_shipments()
|
||||
cls.rma_customer_id.action_view_out_shipments()
|
||||
cls.rma_customer_id.action_view_lines()
|
||||
self.rma_customer_id.action_view_in_shipments()
|
||||
self.rma_customer_id.action_view_out_shipments()
|
||||
self.rma_customer_id.action_view_lines()
|
||||
# Check counts:
|
||||
cls.assertEquals(cls.rma_customer_id.out_shipment_count, 1)
|
||||
cls.assertEquals(cls.rma_customer_id.in_shipment_count, 1)
|
||||
self.assertEquals(self.rma_customer_id.out_shipment_count, 1)
|
||||
self.assertEquals(self.rma_customer_id.in_shipment_count, 1)
|
||||
|
||||
# DROPSHIP
|
||||
def test_03_dropship(cls):
|
||||
def test_03_dropship(self):
|
||||
# Before receiving or creating the delivery from supplier rma:
|
||||
for line in cls.rma_droship_id.rma_line_ids:
|
||||
if line.product_id == cls.product_1:
|
||||
cls.assertEquals(line.qty_to_supplier_rma, 3.0)
|
||||
if line.product_id == cls.product_2:
|
||||
cls.assertEquals(line.qty_to_supplier_rma, 5.0)
|
||||
if line.product_id == cls.product_3:
|
||||
cls.assertEquals(line.qty_to_supplier_rma, 2.0)
|
||||
for line in self.rma_droship_id.rma_line_ids:
|
||||
if line.product_id == self.product_1:
|
||||
self.assertEquals(line.qty_to_supplier_rma, 3.0)
|
||||
if line.product_id == self.product_2:
|
||||
self.assertEquals(line.qty_to_supplier_rma, 5.0)
|
||||
if line.product_id == self.product_3:
|
||||
self.assertEquals(line.qty_to_supplier_rma, 2.0)
|
||||
|
||||
# TODO: receive dropship
|
||||
|
||||
# Create supplier rma:
|
||||
wizard = cls.make_supplier_rma.with_context({
|
||||
'active_ids': cls.rma_droship_id.rma_line_ids.ids,
|
||||
wizard = self.make_supplier_rma.with_context({
|
||||
'active_ids': self.rma_droship_id.rma_line_ids.ids,
|
||||
'active_model': 'rma.order.line',
|
||||
'active_id': 1
|
||||
}).create({})
|
||||
res = wizard.make_supplier_rma()
|
||||
supplier_rma = cls.rma.browse(res['res_id'])
|
||||
supplier_rma = self.rma.browse(res['res_id'])
|
||||
for line in supplier_rma.rma_line_ids:
|
||||
line.action_rma_to_approve()
|
||||
line.action_rma_approve()
|
||||
|
||||
for line in cls.rma_droship_id.rma_line_ids:
|
||||
cls.assertEquals(line.qty_to_supplier_rma, 0.0)
|
||||
if line.product_id == cls.product_1:
|
||||
cls.assertEquals(line.qty_to_receive, 3.0)
|
||||
cls.assertEquals(line.qty_in_supplier_rma, 3.0)
|
||||
if line.product_id == cls.product_2:
|
||||
cls.assertEquals(line.qty_to_receive, 5.0)
|
||||
cls.assertEquals(line.qty_in_supplier_rma, 5.0)
|
||||
if line.product_id == cls.product_3:
|
||||
cls.assertEquals(line.qty_to_receive, 2.0)
|
||||
cls.assertEquals(line.qty_in_supplier_rma, 2.0)
|
||||
for line in self.rma_droship_id.rma_line_ids:
|
||||
self.assertEquals(line.qty_to_supplier_rma, 0.0)
|
||||
if line.product_id == self.product_1:
|
||||
self.assertEquals(line.qty_to_receive, 3.0)
|
||||
self.assertEquals(line.qty_in_supplier_rma, 3.0)
|
||||
if line.product_id == self.product_2:
|
||||
self.assertEquals(line.qty_to_receive, 5.0)
|
||||
self.assertEquals(line.qty_in_supplier_rma, 5.0)
|
||||
if line.product_id == self.product_3:
|
||||
self.assertEquals(line.qty_to_receive, 2.0)
|
||||
self.assertEquals(line.qty_in_supplier_rma, 2.0)
|
||||
|
||||
# Create deliveries from supplier rma:
|
||||
wizard = cls.rma_make_picking.with_context({
|
||||
wizard = self.rma_make_picking.with_context({
|
||||
'active_id': 1,
|
||||
'active_ids': supplier_rma.rma_line_ids.ids,
|
||||
'active_model': 'rma.order.line',
|
||||
@@ -450,50 +452,50 @@ class TestRma(common.SavepointCase):
|
||||
group_ids = set([proc.group_id.id for proc in procurements if
|
||||
proc.group_id])
|
||||
domain = [('group_id', 'in', list(group_ids))]
|
||||
picking = cls.stockpicking.search(domain)
|
||||
cls.assertEquals(len(picking), 1,
|
||||
"Incorrect number of pickings created")
|
||||
picking = self.stockpicking.search(domain)
|
||||
self.assertEquals(len(picking), 1,
|
||||
"Incorrect number of pickings created")
|
||||
moves = picking.move_lines
|
||||
cls.assertEquals(len(moves), 3,
|
||||
"Incorrect number of moves created")
|
||||
self.assertEquals(len(moves), 3,
|
||||
"Incorrect number of moves created")
|
||||
for line in supplier_rma.rma_line_ids:
|
||||
# common qtys for all products
|
||||
cls.assertEquals(line.qty_to_receive, 0, "Wrong qty to receive")
|
||||
cls.assertEquals(line.qty_received, 0, "Wrong qty received")
|
||||
cls.assertEquals(line.qty_incoming, 0, "Wrong qty incoming")
|
||||
cls.assertEquals(line.qty_delivered, 0, "Wrong qty delivered")
|
||||
self.assertEquals(line.qty_to_receive, 0, "Wrong qty to receive")
|
||||
self.assertEquals(line.qty_received, 0, "Wrong qty received")
|
||||
self.assertEquals(line.qty_incoming, 0, "Wrong qty incoming")
|
||||
self.assertEquals(line.qty_delivered, 0, "Wrong qty delivered")
|
||||
# product specific
|
||||
if line.product_id == cls.product_1:
|
||||
cls.assertEquals(
|
||||
if line.product_id == self.product_1:
|
||||
self.assertEquals(
|
||||
line.qty_to_deliver, 3.0, "Wrong qty to deliver")
|
||||
cls.assertEquals(line.qty_outgoing, 3.0)
|
||||
if line.product_id == cls.product_2:
|
||||
cls.assertEquals(line.qty_outgoing, 5.0)
|
||||
if line.product_id == cls.product_3:
|
||||
cls.assertEquals(line.qty_outgoing, 2.0)
|
||||
self.assertEquals(line.qty_outgoing, 3.0)
|
||||
if line.product_id == self.product_2:
|
||||
self.assertEquals(line.qty_outgoing, 5.0)
|
||||
if line.product_id == self.product_3:
|
||||
self.assertEquals(line.qty_outgoing, 2.0)
|
||||
|
||||
for line in cls.rma_droship_id.rma_line_ids:
|
||||
for line in self.rma_droship_id.rma_line_ids:
|
||||
line.action_rma_done()
|
||||
cls.assertEquals(line.state, 'done', "Wrong State")
|
||||
self.assertEquals(line.state, 'done', "Wrong State")
|
||||
|
||||
# Check counts:
|
||||
cls.assertEquals(cls.rma_droship_id.out_shipment_count, 0)
|
||||
cls.assertEquals(supplier_rma.out_shipment_count, 1)
|
||||
cls.assertEquals(supplier_rma.in_shipment_count, 0)
|
||||
self.assertEquals(self.rma_droship_id.out_shipment_count, 0)
|
||||
self.assertEquals(supplier_rma.out_shipment_count, 1)
|
||||
self.assertEquals(supplier_rma.in_shipment_count, 0)
|
||||
|
||||
# Supplier RMA
|
||||
def test_04_supplier_rma(cls):
|
||||
def test_04_supplier_rma(self):
|
||||
# Update quantities:
|
||||
cls.update_product_qty(cls.product_1)
|
||||
cls.update_product_qty(cls.product_2)
|
||||
cls.update_product_qty(cls.product_3)
|
||||
self.update_product_qty(self.product_1)
|
||||
self.update_product_qty(self.product_2)
|
||||
self.update_product_qty(self.product_3)
|
||||
# Check correct RMA type:
|
||||
cls.assertEqual(cls.rma_supplier_id.type, 'supplier')
|
||||
for line in cls.rma_supplier_id.rma_line_ids:
|
||||
cls.assertEqual(line.type, 'supplier')
|
||||
self.assertEqual(self.rma_supplier_id.type, 'supplier')
|
||||
for line in self.rma_supplier_id.rma_line_ids:
|
||||
self.assertEqual(line.type, 'supplier')
|
||||
# Create delivery:
|
||||
wizard = cls.rma_make_picking.with_context({
|
||||
'active_ids': cls.rma_supplier_id.rma_line_ids.ids,
|
||||
wizard = self.rma_make_picking.with_context({
|
||||
'active_ids': self.rma_supplier_id.rma_line_ids.ids,
|
||||
'active_model': 'rma.order.line',
|
||||
'picking_type': 'outgoing',
|
||||
'active_id': 1
|
||||
@@ -502,50 +504,50 @@ class TestRma(common.SavepointCase):
|
||||
group_ids = set([proc.group_id.id for proc in procurements if
|
||||
proc.group_id])
|
||||
domain = [('group_id', 'in', list(group_ids))]
|
||||
picking = cls.stockpicking.search(domain)
|
||||
cls.assertEquals(len(picking), 1,
|
||||
"Incorrect number of pickings created")
|
||||
picking = self.stockpicking.search(domain)
|
||||
self.assertEquals(len(picking), 1,
|
||||
"Incorrect number of pickings created")
|
||||
moves = picking.move_lines
|
||||
cls.assertEquals(len(moves), 3,
|
||||
"Incorrect number of moves created")
|
||||
for line in cls.rma_supplier_id.rma_line_ids:
|
||||
self.assertEquals(len(moves), 3,
|
||||
"Incorrect number of moves created")
|
||||
for line in self.rma_supplier_id.rma_line_ids:
|
||||
# common qtys for all products
|
||||
cls.assertEquals(line.qty_received, 0, "Wrong qty received")
|
||||
cls.assertEquals(line.qty_incoming, 0, "Wrong qty incoming")
|
||||
cls.assertEquals(line.qty_delivered, 0, "Wrong qty delivered")
|
||||
self.assertEquals(line.qty_received, 0, "Wrong qty received")
|
||||
self.assertEquals(line.qty_incoming, 0, "Wrong qty incoming")
|
||||
self.assertEquals(line.qty_delivered, 0, "Wrong qty delivered")
|
||||
# product specific
|
||||
if line.product_id == cls.product_1:
|
||||
cls.assertEquals(
|
||||
if line.product_id == self.product_1:
|
||||
self.assertEquals(
|
||||
line.qty_to_deliver, 3.0, "Wrong qty to deliver")
|
||||
cls.assertEquals(line.qty_to_receive, 3.0)
|
||||
cls.assertEquals(line.qty_outgoing, 3.0)
|
||||
if line.product_id == cls.product_2:
|
||||
cls.assertEquals(line.qty_to_receive, 5.0)
|
||||
cls.assertEquals(line.qty_outgoing, 5.0)
|
||||
if line.product_id == cls.product_3:
|
||||
cls.assertEquals(line.qty_to_receive, 2.0)
|
||||
cls.assertEquals(line.qty_outgoing, 2.0)
|
||||
self.assertEquals(line.qty_to_receive, 3.0)
|
||||
self.assertEquals(line.qty_outgoing, 3.0)
|
||||
if line.product_id == self.product_2:
|
||||
self.assertEquals(line.qty_to_receive, 5.0)
|
||||
self.assertEquals(line.qty_outgoing, 5.0)
|
||||
if line.product_id == self.product_3:
|
||||
self.assertEquals(line.qty_to_receive, 2.0)
|
||||
self.assertEquals(line.qty_outgoing, 2.0)
|
||||
|
||||
# Validate Delivery:
|
||||
picking.action_assign()
|
||||
picking.do_transfer()
|
||||
for line in cls.rma_supplier_id.rma_line_ids:
|
||||
cls.assertEquals(line.qty_incoming, 0, "Wrong qty incoming")
|
||||
cls.assertEquals(line.qty_received, 0, "Wrong qty received")
|
||||
if line.product_id == cls.product_1:
|
||||
cls.assertEquals(line.qty_delivered, 3.0)
|
||||
cls.assertEquals(line.qty_to_receive, 3.0)
|
||||
if line.product_id == cls.product_2:
|
||||
cls.assertEquals(line.qty_delivered, 5.0)
|
||||
cls.assertEquals(line.qty_to_receive, 5.0)
|
||||
if line.product_id == cls.product_3:
|
||||
cls.assertEquals(line.qty_delivered, 2.0)
|
||||
cls.assertEquals(line.qty_to_receive, 2.0)
|
||||
for line in self.rma_supplier_id.rma_line_ids:
|
||||
self.assertEquals(line.qty_incoming, 0, "Wrong qty incoming")
|
||||
self.assertEquals(line.qty_received, 0, "Wrong qty received")
|
||||
if line.product_id == self.product_1:
|
||||
self.assertEquals(line.qty_delivered, 3.0)
|
||||
self.assertEquals(line.qty_to_receive, 3.0)
|
||||
if line.product_id == self.product_2:
|
||||
self.assertEquals(line.qty_delivered, 5.0)
|
||||
self.assertEquals(line.qty_to_receive, 5.0)
|
||||
if line.product_id == self.product_3:
|
||||
self.assertEquals(line.qty_delivered, 2.0)
|
||||
self.assertEquals(line.qty_to_receive, 2.0)
|
||||
|
||||
# Create incoming shipment
|
||||
wizard = cls.rma_make_picking.with_context({
|
||||
wizard = self.rma_make_picking.with_context({
|
||||
'active_id': 1,
|
||||
'active_ids': cls.rma_supplier_id.rma_line_ids.ids,
|
||||
'active_ids': self.rma_supplier_id.rma_line_ids.ids,
|
||||
'active_model': 'rma.order.line',
|
||||
'picking_type': 'incoming',
|
||||
}).create({})
|
||||
@@ -555,47 +557,47 @@ class TestRma(common.SavepointCase):
|
||||
domain = [
|
||||
('group_id', 'in', list(group_ids)),
|
||||
('picking_type_code', '=', 'incoming')]
|
||||
pickings = cls.stockpicking.search(domain)
|
||||
cls.assertEquals(len(pickings), 1,
|
||||
"Incorrect number of pickings created")
|
||||
pickings = self.stockpicking.search(domain)
|
||||
self.assertEquals(len(pickings), 1,
|
||||
"Incorrect number of pickings created")
|
||||
picking_out = pickings[0]
|
||||
moves = picking_out.move_lines
|
||||
cls.assertEquals(len(moves), 3,
|
||||
"Incorrect number of moves created")
|
||||
for line in cls.rma_supplier_id.rma_line_ids:
|
||||
if line.product_id == cls.product_1:
|
||||
cls.assertEquals(
|
||||
self.assertEquals(len(moves), 3,
|
||||
"Incorrect number of moves created")
|
||||
for line in self.rma_supplier_id.rma_line_ids:
|
||||
if line.product_id == self.product_1:
|
||||
self.assertEquals(
|
||||
line.qty_to_receive, 3.0, "Wrong qty to receive")
|
||||
cls.assertEquals(line.qty_incoming, 3.0)
|
||||
cls.assertEquals(line.qty_delivered, 3.0)
|
||||
if line.product_id == cls.product_2:
|
||||
cls.assertEquals(line.qty_incoming, 5.0)
|
||||
cls.assertEquals(line.qty_delivered, 5.0)
|
||||
if line.product_id == cls.product_3:
|
||||
cls.assertEquals(line.qty_incoming, 2.0)
|
||||
cls.assertEquals(line.qty_delivered, 2.0)
|
||||
self.assertEquals(line.qty_incoming, 3.0)
|
||||
self.assertEquals(line.qty_delivered, 3.0)
|
||||
if line.product_id == self.product_2:
|
||||
self.assertEquals(line.qty_incoming, 5.0)
|
||||
self.assertEquals(line.qty_delivered, 5.0)
|
||||
if line.product_id == self.product_3:
|
||||
self.assertEquals(line.qty_incoming, 2.0)
|
||||
self.assertEquals(line.qty_delivered, 2.0)
|
||||
|
||||
# Validate incoming shipment:
|
||||
picking_out.action_assign()
|
||||
picking_out.do_transfer()
|
||||
for line in cls.rma_supplier_id.rma_line_ids[0]:
|
||||
cls.assertEquals(line.qty_to_receive, 0, "Wrong qty to receive")
|
||||
cls.assertEquals(line.qty_incoming, 0, "Wrong qty incoming")
|
||||
cls.assertEquals(line.qty_to_deliver, 0, "Wrong qty to deliver")
|
||||
cls.assertEquals(line.qty_outgoing, 0, "Wrong qty outgoing")
|
||||
if line.product_id == cls.product_1:
|
||||
cls.assertEquals(line.qty_received, 3.0)
|
||||
cls.assertEquals(line.qty_delivered, 3.0)
|
||||
if line.product_id == cls.product_2:
|
||||
cls.assertEquals(line.qty_received, 5.0)
|
||||
cls.assertEquals(line.qty_delivered, 5.0)
|
||||
if line.product_id == cls.product_3:
|
||||
cls.assertEquals(line.qty_received, 2.0)
|
||||
cls.assertEquals(line.qty_delivered, 2.0)
|
||||
for line in cls.rma_supplier_id.rma_line_ids:
|
||||
for line in self.rma_supplier_id.rma_line_ids[0]:
|
||||
self.assertEquals(line.qty_to_receive, 0, "Wrong qty to receive")
|
||||
self.assertEquals(line.qty_incoming, 0, "Wrong qty incoming")
|
||||
self.assertEquals(line.qty_to_deliver, 0, "Wrong qty to deliver")
|
||||
self.assertEquals(line.qty_outgoing, 0, "Wrong qty outgoing")
|
||||
if line.product_id == self.product_1:
|
||||
self.assertEquals(line.qty_received, 3.0)
|
||||
self.assertEquals(line.qty_delivered, 3.0)
|
||||
if line.product_id == self.product_2:
|
||||
self.assertEquals(line.qty_received, 5.0)
|
||||
self.assertEquals(line.qty_delivered, 5.0)
|
||||
if line.product_id == self.product_3:
|
||||
self.assertEquals(line.qty_received, 2.0)
|
||||
self.assertEquals(line.qty_delivered, 2.0)
|
||||
for line in self.rma_supplier_id.rma_line_ids:
|
||||
line.action_rma_done()
|
||||
cls.assertEquals(line.state, 'done', "Wrong State")
|
||||
self.assertEquals(line.state, 'done', "Wrong State")
|
||||
|
||||
# Check counts:
|
||||
cls.assertEquals(cls.rma_supplier_id.out_shipment_count, 1)
|
||||
cls.assertEquals(cls.rma_supplier_id.in_shipment_count, 1)
|
||||
self.assertEquals(self.rma_supplier_id.out_shipment_count, 1)
|
||||
self.assertEquals(self.rma_supplier_id.in_shipment_count, 1)
|
||||
|
||||
@@ -92,10 +92,10 @@ class RmaMakePicking(models.TransientModel):
|
||||
return delivery_address
|
||||
|
||||
@api.model
|
||||
def _get_address_location(self, delivery_address_id, type):
|
||||
if type == 'supplier':
|
||||
def _get_address_location(self, delivery_address_id, rtype):
|
||||
if rtype == 'supplier':
|
||||
return delivery_address_id.property_stock_supplier
|
||||
elif type == 'customer':
|
||||
elif rtype == 'customer':
|
||||
return delivery_address_id.property_stock_customer
|
||||
|
||||
@api.model
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# Copyright 2017-18 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from openerp.tests import common
|
||||
from odoo.tests import common
|
||||
|
||||
|
||||
class TestRmaAccount(common.SingleTransactionCase):
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.tools.safe_eval import safe_eval as eval
|
||||
from odoo.tools.safe_eval import safe_eval as seval
|
||||
import odoo.addons.decimal_precision as dp
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ class RmaRefund(models.TransientModel):
|
||||
new_invoice.type in ['out_refund', 'out_invoice']) \
|
||||
else 'action_invoice_tree2'
|
||||
result = self.env.ref('account.%s' % action).read()[0]
|
||||
invoice_domain = eval(result['domain'])
|
||||
invoice_domain = seval(result['domain'])
|
||||
invoice_domain.append(('id', '=', new_invoice.id))
|
||||
result['domain'] = invoice_domain
|
||||
return result
|
||||
|
||||
@@ -13,5 +13,5 @@
|
||||
"depends": ["rma_account", "rma_analytic"],
|
||||
"data": [
|
||||
],
|
||||
'installable': True,
|
||||
'installable': False,
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
from odoo import _, api, exceptions, models
|
||||
|
||||
|
||||
class AccountInvocieLine(models.Model):
|
||||
class AccountInvoiceLine(models.Model):
|
||||
_inherit = "account.invoice.line"
|
||||
|
||||
@api.constrains('analytic_account_id')
|
||||
|
||||
@@ -15,4 +15,5 @@
|
||||
"views/rma_order_line_view.xml"
|
||||
],
|
||||
'installable': True,
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# © 2018 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
||||
|
||||
from odoo import fields, models
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class RmaOrderLine(models.Model):
|
||||
@@ -13,3 +13,14 @@ class RmaOrderLine(models.Model):
|
||||
comodel_name='account.analytic.account',
|
||||
string='Analytic Account',
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def _prepare_rma_line_from_inv_line(self, line):
|
||||
res = super(
|
||||
RmaOrderLine, self
|
||||
)._prepare_rma_line_from_inv_line(line)
|
||||
if line.account_analytic_id:
|
||||
res.update(
|
||||
analytic_account_id=line.account_analytic_id.id
|
||||
)
|
||||
return res
|
||||
|
||||
@@ -2,55 +2,71 @@
|
||||
# © 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from odoo.tests import common
|
||||
from odoo.addons.rma.tests import test_rma
|
||||
|
||||
|
||||
class TestRmaAnalytic(common.SavepointCase):
|
||||
class TestRmaAnalytic(test_rma.TestRma):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestRmaAnalytic, cls).setUpClass()
|
||||
cls.stock_picking_model = cls.env['stock.picking']
|
||||
cls.rma_line_model = cls.env['rma.order.line']
|
||||
cls.rma_model = cls.env['rma.order']
|
||||
cls.rma_add_stock_move = cls.env['rma_add_stock_move']
|
||||
cls.stock_location = cls.env.ref('stock.stock_location_stock')
|
||||
cls.product_1 = cls.env.ref('product.product_product_25')
|
||||
cls.customer_location = cls.env.ref(
|
||||
'stock.stock_location_customers')
|
||||
cls.product_uom_id = cls.env.ref('product.product_uom_unit')
|
||||
products2move = [(cls.product_1, 3), ]
|
||||
cls.analytic_1 = cls.env['account.analytic.account'].create({
|
||||
'name': 'Test account #1',
|
||||
})
|
||||
cls.partner_id = cls.env.ref('base.res_partner_1')
|
||||
cls.rma_ana_id = cls._create_rma_analytic(
|
||||
products2move, cls.partner_id)
|
||||
cls.rma_add_invoice_wiz = cls.env["rma_add_invoice"]
|
||||
cls.rma_refund_wiz = cls.env["rma.refund"]
|
||||
products2move = [
|
||||
(cls.product_1, 3),
|
||||
(cls.product_2, 5),
|
||||
(cls.product_3, 2),
|
||||
]
|
||||
cls.rma_add_invoice_wiz = cls.env["rma_add_invoice"]
|
||||
cls.rma_ana_id = cls._create_rma_from_move(
|
||||
products2move,
|
||||
"supplier",
|
||||
cls.env.ref("base.res_partner_2"),
|
||||
dropship=False,
|
||||
)
|
||||
receivable_type = cls.env.ref(
|
||||
"account.data_account_type_receivable"
|
||||
)
|
||||
# Create Invoices:
|
||||
customer_account = (
|
||||
cls.env["account.account"]
|
||||
.search(
|
||||
[("user_type_id", "=", receivable_type.id)], limit=1
|
||||
)
|
||||
.id
|
||||
)
|
||||
cls.inv_customer = cls.env["account.invoice"].create(
|
||||
{
|
||||
"partner_id": cls.partner_id.id,
|
||||
"account_id": customer_account,
|
||||
"type": "out_invoice",
|
||||
}
|
||||
)
|
||||
cls.anal = cls.env["account.analytic.account"].create(
|
||||
{"name": "Name"}
|
||||
)
|
||||
cls.inv_line_1 = cls.env["account.invoice.line"].create(
|
||||
{
|
||||
"name": cls.partner_id.name,
|
||||
"product_id": cls.product_1.id,
|
||||
"quantity": 12.0,
|
||||
"price_unit": 100.0,
|
||||
"account_analytic_id": cls.anal.id,
|
||||
"invoice_id": cls.inv_customer.id,
|
||||
"uom_id": cls.product_1.uom_id.id,
|
||||
"account_id": customer_account,
|
||||
}
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def _create_picking(cls, partner):
|
||||
return cls.stock_picking_model.create({
|
||||
'partner_id': partner.id,
|
||||
'picking_type_id': cls.env.ref('stock.picking_type_in').id,
|
||||
'location_id': cls.stock_location.id,
|
||||
'location_dest_id': cls.customer_location.id
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def _prepare_anal_move(cls, product, qty, src, dest, picking_in, analytic):
|
||||
res = {
|
||||
'partner_id': cls.partner_id.id,
|
||||
'product_id': product.id,
|
||||
'name': product.partner_ref,
|
||||
'state': 'confirmed',
|
||||
'product_uom': cls.product_uom_id.id or product.uom_id.id,
|
||||
'product_uom_qty': qty,
|
||||
'origin': 'Test RMA',
|
||||
'location_id': src.id,
|
||||
'location_dest_id': dest.id,
|
||||
'picking_id': picking_in.id,
|
||||
'analytic_account_id': analytic.id,
|
||||
}
|
||||
def _prepare_move(cls, product, qty, src, dest, picking_in):
|
||||
res = super(TestRmaAnalytic, cls)._prepare_move(
|
||||
product, qty, src, dest, picking_in
|
||||
)
|
||||
analytic_1 = cls.env["account.analytic.account"].create(
|
||||
{"name": "Test account #1"}
|
||||
)
|
||||
res.update({"analytic_account_id": analytic_1.id})
|
||||
return res
|
||||
|
||||
@classmethod
|
||||
@@ -59,38 +75,176 @@ class TestRmaAnalytic(common.SavepointCase):
|
||||
moves = []
|
||||
for item in products2move:
|
||||
move_values = cls._prepare_anal_move(
|
||||
item[0], item[1], cls.stock_location,
|
||||
cls.customer_location, picking_in, cls.analytic_1)
|
||||
moves.append(cls.env['stock.move'].create(move_values))
|
||||
item[0],
|
||||
item[1],
|
||||
cls.stock_location,
|
||||
cls.customer_location,
|
||||
picking_in,
|
||||
cls.analytic_1,
|
||||
)
|
||||
moves.append(cls.env["stock.move"].create(move_values))
|
||||
|
||||
rma_id = cls.rma_model.create(
|
||||
{
|
||||
'reference': '0001',
|
||||
'type': 'customer',
|
||||
'partner_id': partner.id,
|
||||
'company_id': cls.env.ref('base.main_company').id
|
||||
})
|
||||
"reference": "0001",
|
||||
"type": "customer",
|
||||
"partner_id": partner.id,
|
||||
"company_id": cls.env.ref("base.main_company").id,
|
||||
}
|
||||
)
|
||||
for move in moves:
|
||||
wizard = cls.rma_add_stock_move.with_context(
|
||||
{'stock_move_id': move.id, 'customer': True,
|
||||
'active_ids': rma_id.id,
|
||||
'active_model': 'rma.order',
|
||||
}
|
||||
{
|
||||
"stock_move_id": move.id,
|
||||
"customer": True,
|
||||
"active_ids": rma_id.id,
|
||||
"active_model": "rma.order",
|
||||
}
|
||||
).create({})
|
||||
data = wizard._prepare_rma_line_from_stock_move(move)
|
||||
wizard.add_lines()
|
||||
|
||||
for operation in move.product_id.rma_customer_operation_id:
|
||||
operation.in_route_id = False
|
||||
if move.product_id.rma_customer_operation_id:
|
||||
move.product_id.rma_customer_operation_id.in_route_id = False
|
||||
move.product_id.categ_id.rma_customer_operation_id = False
|
||||
move.product_id.rma_customer_operation_id = False
|
||||
wizard._prepare_rma_line_from_stock_move(move)
|
||||
cls.line = cls.rma_line_model.create(data)
|
||||
return rma_id
|
||||
|
||||
def test_analytic(cls):
|
||||
for line in cls.rma_ana_id.rma_line_ids:
|
||||
def test_analytic(self):
|
||||
for line in self.rma_ana_id.rma_line_ids:
|
||||
for move in line.move_ids:
|
||||
cls.assertEqual(
|
||||
line.analytic_account_id, move.analytic_account_id,
|
||||
"the analytic account is not propagated")
|
||||
self.assertEqual(
|
||||
line.analytic_account_id,
|
||||
move.analytic_account_id,
|
||||
"the analytic account is not propagated",
|
||||
)
|
||||
|
||||
def test_invoice_analytic(self):
|
||||
"""Test wizard to create RMA from a customer invoice."""
|
||||
rma_line = (
|
||||
self.env["rma.order.line"]
|
||||
.with_context(customer=True)
|
||||
.new(
|
||||
{
|
||||
"partner_id": self.partner_id.id,
|
||||
"product_id": self.product_1.id,
|
||||
"operation_id": self.env.ref(
|
||||
"rma.rma_operation_customer_replace"
|
||||
).id,
|
||||
"in_route_id": self.env.ref(
|
||||
"rma.route_rma_customer"
|
||||
),
|
||||
"out_route_id": self.env.ref(
|
||||
"rma.route_rma_customer"
|
||||
),
|
||||
"in_warehouse_id": self.env.ref(
|
||||
"stock.warehouse0"
|
||||
),
|
||||
"out_warehouse_id": self.env.ref(
|
||||
"stock.warehouse0"
|
||||
),
|
||||
"location_id": self.env.ref(
|
||||
"stock.stock_location_stock"
|
||||
),
|
||||
"type": "customer",
|
||||
"invoice_line_id": self.inv_line_1.id,
|
||||
"uom_id": self.product_1.uom_id.id,
|
||||
}
|
||||
)
|
||||
)
|
||||
rma_line._onchange_invoice_line_id()
|
||||
self.assertEqual(
|
||||
rma_line.analytic_account_id,
|
||||
self.inv_line_1.account_analytic_id,
|
||||
)
|
||||
|
||||
def test_invoice_analytic02(self):
|
||||
self.product_1.rma_customer_operation_id = self.env.ref(
|
||||
"rma.rma_operation_customer_replace"
|
||||
).id
|
||||
rma_order = (
|
||||
self.env["rma.order"]
|
||||
.with_context(customer=True)
|
||||
.create(
|
||||
{
|
||||
"name": "RMA",
|
||||
"partner_id": self.partner_id.id,
|
||||
"type": "customer",
|
||||
"rma_line_ids": [],
|
||||
}
|
||||
)
|
||||
)
|
||||
add_inv = self.rma_add_invoice_wiz.with_context(
|
||||
{
|
||||
"customer": True,
|
||||
"active_ids": [rma_order.id],
|
||||
"active_model": "rma.order",
|
||||
}
|
||||
).create(
|
||||
{
|
||||
"invoice_line_ids": [
|
||||
(6, 0, self.inv_customer.invoice_line_ids.ids)
|
||||
]
|
||||
}
|
||||
)
|
||||
add_inv.add_lines()
|
||||
|
||||
self.assertEqual(
|
||||
rma_order.mapped("rma_line_ids.analytic_account_id"),
|
||||
self.inv_line_1.account_analytic_id,
|
||||
)
|
||||
|
||||
def test_refund_analytic(self):
|
||||
self.product_1.rma_customer_operation_id = self.env.ref(
|
||||
"rma_account.rma_operation_customer_refund"
|
||||
).id
|
||||
rma_line = (
|
||||
self.env["rma.order.line"]
|
||||
.with_context(customer=True)
|
||||
.create(
|
||||
{
|
||||
"partner_id": self.partner_id.id,
|
||||
"product_id": self.product_1.id,
|
||||
"operation_id": self.env.ref(
|
||||
"rma_account.rma_operation_customer_refund"
|
||||
).id,
|
||||
"in_route_id": self.env.ref(
|
||||
"rma.route_rma_customer"
|
||||
).id,
|
||||
"out_route_id": self.env.ref(
|
||||
"rma.route_rma_customer"
|
||||
).id,
|
||||
"in_warehouse_id": self.env.ref(
|
||||
"stock.warehouse0"
|
||||
).id,
|
||||
"out_warehouse_id": self.env.ref(
|
||||
"stock.warehouse0"
|
||||
).id,
|
||||
"location_id": self.env.ref(
|
||||
"stock.stock_location_stock"
|
||||
).id,
|
||||
"type": "customer",
|
||||
"invoice_line_id": self.inv_line_1.id,
|
||||
"delivery_policy": "no",
|
||||
"receipt_policy": "ordered",
|
||||
"uom_id": self.product_1.uom_id.id,
|
||||
}
|
||||
)
|
||||
)
|
||||
rma_line._onchange_invoice_line_id()
|
||||
rma_line.action_rma_to_approve()
|
||||
rma_line.action_rma_approve()
|
||||
make_refund = self.rma_refund_wiz.with_context(
|
||||
{
|
||||
"customer": True,
|
||||
"active_ids": rma_line.ids,
|
||||
"active_model": "rma.order.line",
|
||||
}
|
||||
).create({"description": "Test refund"})
|
||||
make_refund.invoice_refund()
|
||||
self.assertEqual(
|
||||
rma_line.mapped("analytic_account_id"),
|
||||
rma_line.mapped("refund_line_ids.account_analytic_id"),
|
||||
)
|
||||
|
||||
@@ -4,3 +4,5 @@
|
||||
|
||||
from . import rma_add_stock_move
|
||||
from . import rma_make_picking
|
||||
from . import rma_add_invoice
|
||||
from . import rma_refund
|
||||
|
||||
19
rma_analytic/wizards/rma_add_invoice.py
Normal file
19
rma_analytic/wizards/rma_add_invoice.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# -*- 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 odoo import models
|
||||
|
||||
|
||||
class RmaAddInvoice(models.TransientModel):
|
||||
_inherit = "rma_add_invoice"
|
||||
|
||||
def _prepare_rma_line_from_inv_line(self, line):
|
||||
res = super(
|
||||
RmaAddInvoice, self
|
||||
)._prepare_rma_line_from_inv_line(line)
|
||||
if line.account_analytic_id:
|
||||
res.update(
|
||||
analytic_account_id=line.account_analytic_id.id
|
||||
)
|
||||
return res
|
||||
18
rma_analytic/wizards/rma_refund.py
Normal file
18
rma_analytic/wizards/rma_refund.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# -*- 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 odoo import api, models
|
||||
|
||||
|
||||
class RmaRefund(models.TransientModel):
|
||||
_inherit = "rma.refund"
|
||||
|
||||
@api.model
|
||||
def prepare_refund_line(self, item, refund):
|
||||
res = super(RmaRefund, self).prepare_refund_line(item, refund)
|
||||
if item.line_id.analytic_account_id:
|
||||
res.update(
|
||||
account_analytic_id=item.line_id.analytic_account_id.id
|
||||
)
|
||||
return res
|
||||
@@ -2,7 +2,7 @@
|
||||
# Copyright 2017-18 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, models
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class PurchaseOrder(models.Model):
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
# Copyright 2018 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, _
|
||||
from openerp.exceptions import ValidationError
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class RmaOperation(models.Model):
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
# Copyright 2017-18 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from openerp.tests import common
|
||||
from openerp.fields import Datetime
|
||||
from odoo.tests import common
|
||||
from odoo.fields import Datetime
|
||||
|
||||
|
||||
class TestRmaPurchase(common.SingleTransactionCase):
|
||||
|
||||
@@ -21,6 +21,8 @@ class RmaLineMakePurchaseOrder(models.TransientModel):
|
||||
|
||||
@api.model
|
||||
def _prepare_purchase_order_line(self, po, item):
|
||||
res = super(RmaLineMakePurchaseOrder, self)._prepare_purchase_order_line(po, item)
|
||||
res = super(
|
||||
RmaLineMakePurchaseOrder, self)._prepare_purchase_order_line(
|
||||
po, item)
|
||||
res['account_analytic_id'] = item.line_id.analytic_account_id.id
|
||||
return res
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# © 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
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class QualityControlIssue(models.Model):
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# © 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
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class RmaOrderLine(models.Model):
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# © 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from openerp.tests import common
|
||||
from odoo.tests import common
|
||||
|
||||
|
||||
class TestRma(common.TransactionCase):
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
# Copyright 2016 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0).
|
||||
|
||||
import openerp.addons.decimal_precision as dp
|
||||
from openerp import api, fields, models, _
|
||||
from openerp.exceptions import ValidationError
|
||||
import odoo.addons.decimal_precision as dp
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class QcIssueMakeSupplierRma(models.TransientModel):
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# 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
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class MrpRepair(models.Model):
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# 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
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class RmaOperation(models.Model):
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# 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 api, fields, models
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class RmaOrder(models.Model):
|
||||
|
||||
@@ -2,8 +2,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 api, fields, models
|
||||
from openerp.addons import decimal_precision as dp
|
||||
from odoo import api, fields, models
|
||||
from odoo.addons import decimal_precision as dp
|
||||
|
||||
|
||||
class RmaOrderLine(models.Model):
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# © 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from openerp.tests import common
|
||||
from odoo.tests import common
|
||||
|
||||
|
||||
class TestRma(common.TransactionCase):
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0).
|
||||
|
||||
import openerp.addons.decimal_precision as dp
|
||||
from openerp import _, api, fields, models
|
||||
from openerp.exceptions import ValidationError
|
||||
import odoo.addons.decimal_precision as dp
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class RmaLineMakeRepair(models.TransientModel):
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# Copyright 2017-18 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from openerp.tests import common
|
||||
from odoo.tests import common
|
||||
|
||||
|
||||
class TestRmaSale(common.SingleTransactionCase):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright 2016 Eficent Business and IT Consulting Services S.L.
|
||||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) -->
|
||||
<openerp>
|
||||
<odoo>
|
||||
<data>
|
||||
<record id="view_rma_order_line_make_sale_order" model="ir.ui.view">
|
||||
<field name="name">RMA Line Make Sale Order</field>
|
||||
@@ -71,5 +71,5 @@
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
</odoo>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user