mirror of
https://github.com/OCA/rma.git
synced 2025-02-16 17:11:47 +02:00
[FIX] rma: RMA quantities are not quantities on hand
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
"report/report.xml",
|
"report/report.xml",
|
||||||
"data/mail_data.xml",
|
"data/mail_data.xml",
|
||||||
"data/rma_operation_data.xml",
|
"data/rma_operation_data.xml",
|
||||||
|
"data/stock_data.xml",
|
||||||
"security/rma_security.xml",
|
"security/rma_security.xml",
|
||||||
"security/ir.model.access.csv",
|
"security/ir.model.access.csv",
|
||||||
"wizard/stock_picking_return_views.xml",
|
"wizard/stock_picking_return_views.xml",
|
||||||
|
|||||||
9
rma/data/stock_data.xml
Normal file
9
rma/data/stock_data.xml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<data noupdate="1">
|
||||||
|
<record id="stock_location_rma" model="stock.location">
|
||||||
|
<field name="name">RMA</field>
|
||||||
|
<field name="location_id" ref="stock.stock_location_locations"/>
|
||||||
|
<field name="usage">view</field>
|
||||||
|
<field name="company_id"></field>
|
||||||
|
</record>
|
||||||
|
</data>
|
||||||
@@ -22,11 +22,10 @@ def post_init_hook(cr, registry):
|
|||||||
|
|
||||||
def create_rma_locations(warehouse):
|
def create_rma_locations(warehouse):
|
||||||
stock_location = env['stock.location']
|
stock_location = env['stock.location']
|
||||||
location_vals = warehouse._get_locations_values({})
|
if not warehouse.rma_loc_id:
|
||||||
for field_name, values in location_vals.items():
|
rma_location_vals = warehouse._get_rma_location_values()
|
||||||
if field_name == 'rma_loc_id' and not warehouse.rma_loc_id:
|
|
||||||
warehouse.rma_loc_id = stock_location.with_context(
|
warehouse.rma_loc_id = stock_location.with_context(
|
||||||
active_test=False).create(values).id
|
active_test=False).create(rma_location_vals).id
|
||||||
|
|
||||||
def create_rma_picking_types(whs):
|
def create_rma_picking_types(whs):
|
||||||
ir_sequence_sudo = env['ir.sequence'].sudo()
|
ir_sequence_sudo = env['ir.sequence'].sudo()
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# Copyright 2020 Tecnativa - Ernesto Tejeda
|
# Copyright 2020 Tecnativa - Ernesto Tejeda
|
||||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from odoo import fields, models, _
|
from odoo import api, fields, models, _
|
||||||
|
|
||||||
|
|
||||||
class StockWarehouse(models.Model):
|
class StockWarehouse(models.Model):
|
||||||
@@ -27,19 +27,33 @@ class StockWarehouse(models.Model):
|
|||||||
string='RMA Location',
|
string='RMA Location',
|
||||||
)
|
)
|
||||||
|
|
||||||
def _get_locations_values(self, vals):
|
@api.model_create_multi
|
||||||
values = super()._get_locations_values(vals)
|
def create(self, vals_list):
|
||||||
values.update({
|
""" To create an RMA location and link it with a new warehouse,
|
||||||
'rma_loc_id': {
|
this method is overridden instead of '_get_locations_values'
|
||||||
'name': 'RMA',
|
method because the locations that are created with the
|
||||||
|
values returned by that method are forced to be children
|
||||||
|
of view_location_id, and we don't want that.
|
||||||
|
"""
|
||||||
|
res = super().create(vals_list)
|
||||||
|
stock_location = self.env['stock.location']
|
||||||
|
for record in res:
|
||||||
|
rma_location_vals = record._get_rma_location_values()
|
||||||
|
record.rma_loc_id = stock_location.create(rma_location_vals).id
|
||||||
|
return res
|
||||||
|
|
||||||
|
def _get_rma_location_values(self):
|
||||||
|
""" this method is intended to be used by 'create' method
|
||||||
|
to create a new RMA location to be linked to a new warehouse.
|
||||||
|
"""
|
||||||
|
return {
|
||||||
|
'name': self.view_location_id.name,
|
||||||
'active': True,
|
'active': True,
|
||||||
'return_location': True,
|
'return_location': True,
|
||||||
'usage': 'internal',
|
'usage': 'internal',
|
||||||
'company_id': vals.get('company_id', self.company_id.id),
|
'company_id': self.company_id.id,
|
||||||
'location_id': self.view_location_id.id,
|
'location_id': self.env.ref("rma.stock_location_rma").id,
|
||||||
},
|
}
|
||||||
})
|
|
||||||
return values
|
|
||||||
|
|
||||||
def _get_sequence_values(self):
|
def _get_sequence_values(self):
|
||||||
values = super()._get_sequence_values()
|
values = super()._get_sequence_values()
|
||||||
|
|||||||
@@ -656,3 +656,10 @@ class TestRma(SavepointCase):
|
|||||||
})
|
})
|
||||||
self.assertFalse(warehouse.rma_in_type_id.use_create_lots)
|
self.assertFalse(warehouse.rma_in_type_id.use_create_lots)
|
||||||
self.assertTrue(warehouse.rma_in_type_id.use_existing_lots)
|
self.assertTrue(warehouse.rma_in_type_id.use_existing_lots)
|
||||||
|
|
||||||
|
def test_quantities_on_hand(self):
|
||||||
|
rma = self._create_rma(self.partner, self.product, 10, self.rma_loc)
|
||||||
|
rma.action_confirm()
|
||||||
|
rma.reception_move_id.quantity_done = 10
|
||||||
|
rma.reception_move_id.picking_id.action_done()
|
||||||
|
self.assertEqual(rma.product_id.qty_available, 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user