mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[9.0][IMP] rma_purchase:
* remove unneded copy and ondelete attributes. * simplify action_view methods. * fix rma line supplier view. * fix wizard. * extend README. * minor extra fixes.
This commit is contained in:
@@ -1,16 +1,25 @@
|
||||
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg
|
||||
:alt: License LGPL-3
|
||||
|
||||
============
|
||||
RMA Purchase
|
||||
============
|
||||
|
||||
Purchase as RMA source
|
||||
This modules extend the RMA functionality allowing to use Purchase Orders as
|
||||
a RMA source.
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
select add_purchase_id to fill rma from RMA purchase
|
||||
To add lines to a RMA from PO act as follows:
|
||||
|
||||
#. Go to a supplier RMA.
|
||||
#. Fill the *Supplier* field.
|
||||
#. Click on *Add From Purchase Order*.
|
||||
#. Select the Purchase Order.
|
||||
#. Click on *Add an item* and select the lines you would like to add to the
|
||||
RMA.
|
||||
#. Hit *Confirm*.
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
@@ -20,7 +29,6 @@ Bugs are tracked on `GitHub Issues
|
||||
check there if your issue has already been reported. If you spotted it first,
|
||||
help us smashing it by providing a detailed and welcomed feedback.
|
||||
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
@@ -29,7 +37,7 @@ Contributors
|
||||
|
||||
* Jordi Ballester Alomar <jordi.ballester@eficent.com>
|
||||
* Aaron Henriquez <ahenriquez@eficent.com>
|
||||
|
||||
* Lois Rilo <lois.rilo@eficent.com>
|
||||
|
||||
Maintainer
|
||||
----------
|
||||
|
||||
@@ -11,51 +11,34 @@ class RmaOrder(models.Model):
|
||||
@api.multi
|
||||
def _compute_po_count(self):
|
||||
for rec in self:
|
||||
purchase_list = []
|
||||
for line in rec.rma_line_ids:
|
||||
for procurement_id in line.procurement_ids:
|
||||
if procurement_id.purchase_id and \
|
||||
procurement_id.purchase_id.id:
|
||||
purchase_list.append(procurement_id.purchase_id.id)
|
||||
rec.po_count = len(list(set(purchase_list)))
|
||||
purchases = rec.mapped('rma_line_ids.procurement_ids.purchase_id')
|
||||
rec.po_count = len(purchases)
|
||||
|
||||
@api.multi
|
||||
def _compute_origin_po_count(self):
|
||||
po_list = []
|
||||
for rec in self:
|
||||
for rma_line in rec.rma_line_ids:
|
||||
if rma_line.purchase_order_line_id and \
|
||||
rma_line.purchase_order_line_id.id:
|
||||
po_list.append(rma_line.purchase_order_line_id.order_id.id)
|
||||
self.origin_po_count = len(list(set(po_list)))
|
||||
for rma in self:
|
||||
purchases = rma.mapped(
|
||||
'rma_line_ids.purchase_order_line_id.order_id')
|
||||
rma.origin_po_count = len(purchases)
|
||||
|
||||
po_count = fields.Integer(compute=_compute_po_count,
|
||||
string='# of PO',
|
||||
copy=False, default=0)
|
||||
|
||||
origin_po_count = fields.Integer(compute=_compute_origin_po_count,
|
||||
string='# of Origin PO', copy=False,
|
||||
default=0)
|
||||
po_count = fields.Integer(
|
||||
compute='_compute_po_count', string='# of PO')
|
||||
origin_po_count = fields.Integer(
|
||||
compute='_compute_origin_po_count', string='# of Origin PO')
|
||||
|
||||
@api.multi
|
||||
def action_view_purchase_order(self):
|
||||
action = self.env.ref('purchase.purchase_rfq')
|
||||
result = action.read()[0]
|
||||
order_ids = []
|
||||
for line in self.rma_line_ids:
|
||||
for procurement_id in line.procurement_ids:
|
||||
order_ids.append(procurement_id.purchase_id.id)
|
||||
result['domain'] = [('id', 'in', order_ids)]
|
||||
po_ids = self.mapped('rma_line_ids.procurement_ids.purchase_id').ids
|
||||
result['domain'] = [('id', 'in', po_ids)]
|
||||
return result
|
||||
|
||||
@api.multi
|
||||
def action_view_origin_purchase_order(self):
|
||||
action = self.env.ref('purchase.purchase_rfq')
|
||||
result = action.read()[0]
|
||||
order_ids = []
|
||||
for rma_line in self.rma_line_ids:
|
||||
if rma_line.purchase_order_line_id and \
|
||||
rma_line.purchase_order_line_id.id:
|
||||
order_ids.append(rma_line.purchase_order_line_id.order_id.id)
|
||||
result['domain'] = [('id', 'in', order_ids)]
|
||||
po_ids = self.mapped(
|
||||
'rma_line_ids.purchase_order_line_id.order_id').ids
|
||||
result['domain'] = [('id', 'in', po_ids)]
|
||||
return result
|
||||
|
||||
@@ -35,22 +35,20 @@ class RmaOrderLine(models.Model):
|
||||
for rec in self:
|
||||
rec.qty_purchased = rec._get_rma_purchased_qty()
|
||||
|
||||
purchase_count = fields.Integer(compute=_compute_purchase_count,
|
||||
string='# of Purchases', copy=False,
|
||||
default=0)
|
||||
purchase_order_line_id = fields.Many2one('purchase.order.line',
|
||||
string='Origin Purchase Line',
|
||||
purchase_count = fields.Integer(
|
||||
compute='_compute_purchase_count', string='# of Purchases')
|
||||
purchase_order_line_id = fields.Many2one(
|
||||
comodel_name='purchase.order.line', string='Origin Purchase Line',
|
||||
ondelete='restrict')
|
||||
purchase_order_line_ids = fields.Many2many(
|
||||
'purchase.order.line', 'purchase_line_rma_line_rel',
|
||||
'rma_order_line_id', 'purchase_order_line_id',
|
||||
string='Purchase Order Lines', compute=_get_purchase_order_lines)
|
||||
|
||||
comodel_name='purchase.order.line',
|
||||
relation='purchase_line_rma_line_rel',
|
||||
column1='rma_order_line_id', column2='purchase_order_line_id',
|
||||
string='Purchase Order Lines', compute='_get_purchase_order_lines')
|
||||
qty_purchased = fields.Float(
|
||||
string='Qty Purchased', copy=False,
|
||||
digits=dp.get_precision('Product Unit of Measure'),
|
||||
readonly=True, compute=_compute_qty_purchased,
|
||||
store=True)
|
||||
readonly=True, compute='_compute_qty_purchased', store=True)
|
||||
|
||||
@api.multi
|
||||
def action_view_purchase_order(self):
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<odoo>
|
||||
|
||||
<record id="view_rma_line_form" model="ir.ui.view">
|
||||
<field name="name">rma.order.line.supplier.form</field>
|
||||
@@ -29,5 +28,4 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
</odoo>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<odoo>
|
||||
|
||||
<record id="view_rma_supplier_form" model="ir.ui.view">
|
||||
<field name="name">rma.order.supplier.form</field>
|
||||
@@ -29,5 +28,4 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
</odoo>
|
||||
|
||||
@@ -27,21 +27,17 @@ class RmaAddPurchase(models.TransientModel):
|
||||
res['purchase_line_ids'] = False
|
||||
return res
|
||||
|
||||
rma_id = fields.Many2one('rma.order',
|
||||
string='RMA Order',
|
||||
readonly=True,
|
||||
ondelete='cascade')
|
||||
|
||||
partner_id = fields.Many2one(comodel_name='res.partner', string='Partner',
|
||||
readonly=True)
|
||||
rma_id = fields.Many2one(
|
||||
comodel_name='rma.order', string='RMA Order', readonly=True)
|
||||
partner_id = fields.Many2one(
|
||||
comodel_name='res.partner', string='Partner', readonly=True)
|
||||
purchase_id = fields.Many2one(
|
||||
comodel_name='purchase.order', string='Order')
|
||||
purchase_line_ids = fields.Many2many(
|
||||
'purchase.order.line',
|
||||
'rma_add_purchase_add_line_rel',
|
||||
'purchase_line_id', 'rma_add_purchase_id',
|
||||
readonly=False,
|
||||
string='Purcahse Order Lines')
|
||||
comodel_name='purchase.order.line',
|
||||
relation='rma_add_purchase_add_line_rel',
|
||||
column1='rma_add_purchase_id', column2='purchase_line_id',
|
||||
readonly=False, string='Purchase Order Lines')
|
||||
|
||||
def _prepare_rma_line_from_po_line(self, line):
|
||||
if self.env.context.get('customer'):
|
||||
@@ -50,17 +46,6 @@ class RmaAddPurchase(models.TransientModel):
|
||||
else:
|
||||
operation = line.product_id.rma_supplier_operation_id or \
|
||||
line.product_id.categ_id.rma_supplier_operation_id
|
||||
data = {
|
||||
'purchase_order_line_id': line.id,
|
||||
'product_id': line.product_id.id,
|
||||
'origin': line.order_id.name,
|
||||
'uom_id': line.product_uom.id,
|
||||
'operation_id': operation,
|
||||
'product_qty': line.product_qty,
|
||||
'price_unit': line.currency_id.compute(
|
||||
line.price_unit, line.currency_id, round=False),
|
||||
'rma_id': self.rma_id.id
|
||||
}
|
||||
if not operation:
|
||||
operation = self.env['rma.operation'].search(
|
||||
[('type', '=', self.rma_id.type)], limit=1)
|
||||
@@ -70,17 +55,35 @@ class RmaAddPurchase(models.TransientModel):
|
||||
route = self.env['stock.location.route'].search(
|
||||
[('rma_selectable', '=', True)], limit=1)
|
||||
if not route:
|
||||
raise ValidationError("Please define an rma route")
|
||||
data.update(
|
||||
{'in_route_id': operation.in_route_id.id or route,
|
||||
raise ValidationError("Please define a 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 = {
|
||||
'purchase_order_line_id': line.id,
|
||||
'product_id': line.product_id.id,
|
||||
'origin': line.order_id.name,
|
||||
'uom_id': line.product_uom.id,
|
||||
'operation_id': operation.id,
|
||||
'product_qty': line.product_qty,
|
||||
'price_unit': line.currency_id.compute(
|
||||
line.price_unit, line.currency_id, round=False),
|
||||
'rma_id': self.rma_id.id,
|
||||
'in_route_id': operation.in_route_id.id or route,
|
||||
'out_route_id': operation.out_route_id.id or route,
|
||||
'receipt_policy': operation.receipt_policy,
|
||||
'location_id': operation.location_id.id or
|
||||
self.env.ref('stock.stock_location_stock').id,
|
||||
'operation_id': operation.id,
|
||||
'location_id': (operation.location_id.id or
|
||||
operation.in_warehouse_id.lot_rma_id.id or
|
||||
warehouse.lot_rma_id.id),
|
||||
'refund_policy': operation.refund_policy,
|
||||
'delivery_policy': operation.delivery_policy
|
||||
})
|
||||
'delivery_policy': operation.delivery_policy,
|
||||
'in_warehouse_id': operation.in_warehouse_id.id or warehouse.id,
|
||||
'out_warehouse_id': operation.out_warehouse_id.id or warehouse.id,
|
||||
}
|
||||
return data
|
||||
|
||||
@api.model
|
||||
|
||||
Reference in New Issue
Block a user