[9.0][FIX] rma: create supplier rma wizard

This commit is contained in:
lreficent
2017-11-09 17:48:55 +01:00
committed by Jasmin Solanki
parent 8053698eec
commit 55659b3cb3
2 changed files with 40 additions and 42 deletions

View File

@@ -3,7 +3,7 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
import openerp.addons.decimal_precision as dp
from openerp import _, api, exceptions, fields, models
from openerp import _, api, fields, models
from openerp.exceptions import ValidationError
@@ -11,16 +11,17 @@ class RmaLineMakeSupplierRma(models.TransientModel):
_name = "rma.order.line.make.supplier.rma"
_description = "RMA Line Make Supplier RMA"
partner_id = fields.Many2one('res.partner', string='Supplier',
required=False,
domain=[('supplier', '=', True)])
partner_id = fields.Many2one(
comodel_name='res.partner', string='Supplier',
domain=[('supplier', '=', True)], required=True,
)
item_ids = fields.One2many(
'rma.order.line.make.supplier.rma.item',
'wiz_id', string='Items')
supplier_rma_id = fields.Many2one('rma.order',
string='Supplier RMA Order',
required=False,
domain=[('state', '=', 'draft')])
comodel_name='rma.order.line.make.supplier.rma.item',
inverse_name='wiz_id', string='Items',
)
supplier_rma_id = fields.Many2one(
comodel_name='rma.order', string='Supplier RMA Order Group',
)
@api.model
def _prepare_item(self, line):
@@ -50,12 +51,11 @@ class RmaLineMakeSupplierRma(models.TransientModel):
items.append([0, 0, self._prepare_item(line)])
suppliers = lines.mapped('supplier_address_id')
if len(suppliers) == 0:
raise exceptions.Warning(
_('Please specify a supplier address'))
pass
elif len(suppliers) == 1:
res['partner_id'] = suppliers.id
else:
raise exceptions.Warning(
raise ValidationError(
_('Only RMA lines from the same supplier address can be '
'processed at the same time'))
res['item_ids'] = items
@@ -64,8 +64,7 @@ class RmaLineMakeSupplierRma(models.TransientModel):
@api.model
def _prepare_supplier_rma(self, company):
if not self.partner_id:
raise exceptions.Warning(
_('Enter a supplier.'))
raise ValidationError(_('Enter a supplier.'))
return {
'partner_id': self.partner_id.id,
'delivery_address_id': self.partner_id.id,
@@ -77,7 +76,20 @@ class RmaLineMakeSupplierRma(models.TransientModel):
def _prepare_supplier_rma_line(self, rma, item):
operation = self.env['rma.operation'].search(
[('type', '=', 'supplier')], limit=1)
if not operation.in_route_id or not operation.out_route_id:
route = self.env['stock.location.route'].search(
[('rma_selectable', '=', True)], limit=1)
if not route:
raise ValidationError(_("Please define an RMA route"))
if not operation.in_warehouse_id or not operation.out_warehouse_id:
warehouse = self.env['stock.warehouse'].search(
[('company_id', '=', self.rma_id.company_id.id),
('lot_rma_id', '!=', False)], limit=1)
if not warehouse:
raise ValidationError(
_("Please define a warehouse with a default RMA location"))
data = {
'partner_id': self.partner_id.id,
'type': 'supplier',
'origin': item.line_id.rma_id.name,
'delivery_address_id':
@@ -91,28 +103,14 @@ class RmaLineMakeSupplierRma(models.TransientModel):
'receipt_policy': operation.receipt_policy,
'delivery_policy': operation.delivery_policy,
'supplier_to_customer': operation.supplier_to_customer,
}
if not operation.in_route_id or not operation.out_route_id:
route = self.env['stock.location.route'].search(
[('rma_selectable', '=', True)], limit=1)
if not route:
raise ValidationError(_("Please define an rma route"))
if not operation.in_warehouse_id or not operation.out_warehouse_id:
warehouse = self.env['stock.warehouse'].search(
[('company_id', '=', self.rma_id.company_id.id),
('lot_rma_id', '!=', False)], limit=1)
if not warehouse:
raise ValidationError(_("Please define a warehouse with a"
" default rma location"))
data.update(
{'in_warehouse_id': operation.in_warehouse_id.id or warehouse.id,
'out_warehouse_id': operation.out_warehouse_id.id or warehouse.id,
'in_route_id': operation.in_route_id.id or route.id,
'out_route_id': operation.out_route_id.id or route.id,
'location_id': (operation.location_id.id or
operation.in_warehouse_id.lot_rma_id.id or
warehouse.lot_rma_id.id)
})
'in_warehouse_id': operation.in_warehouse_id.id or warehouse.id,
'out_warehouse_id': operation.out_warehouse_id.id or warehouse.id,
'in_route_id': operation.in_route_id.id or route.id,
'out_route_id': operation.out_route_id.id or route.id,
'location_id': (operation.location_id.id or
operation.in_warehouse_id.lot_rma_id.id or
warehouse.lot_rma_id.id)
}
return data
@api.multi
@@ -125,7 +123,7 @@ class RmaLineMakeSupplierRma(models.TransientModel):
for item in self.item_ids:
line = item.line_id
if item.product_qty <= 0.0:
raise exceptions.Warning(
raise ValidationError(
_('Enter a positive quantity.'))
if self.supplier_rma_id:
@@ -167,5 +165,5 @@ class RmaLineMakeRmaOrderItem(models.TransientModel):
related='line_id.product_id', readony=True)
name = fields.Char(related='line_id.name', readonly=True)
uom_id = fields.Many2one('product.uom', string='UoM', readonly=True)
product_qty = fields.Float(string='Quantity to sell',
product_qty = fields.Float(string='Quantity',
digits=dp.get_precision('Product UoS'))

View File

@@ -50,7 +50,7 @@
<record id="action_rma_order_line_make_supplier_rma"
model="ir.actions.act_window">
<field name="name">Create Supplier RMA</field>
<field name="name">Create Supplier RMA Group</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">rma.order.line.make.supplier.rma</field>
<field name="view_type">form</field>
@@ -61,7 +61,7 @@
<record model="ir.values" id="rma_order_line_make_supplier_rma">
<field name="model_id" ref="model_rma_order_line" />
<field name="name">Create Supplier RMA</field>
<field name="name">Create Supplier RMA Group</field>
<field name="key2">client_action_multi</field>
<field name="value"
eval="'ir.actions.act_window,' + str(ref('action_rma_order_line_make_supplier_rma'))" />
@@ -77,7 +77,7 @@
<header position="inside">
<button name="%(action_rma_order_line_make_supplier_rma)d"
states="approved"
string="Create Supplier RMA" class="oe_highlight"
string="Create Supplier RMA Group" class="oe_highlight"
type="action"/>
</header>
</field>