mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
Merge pull request #69 from murtuzasaleh/rma_purchase_v12
[MIG][12.0] rma_purchase
This commit is contained in:
47
rma_purchase/README.rst
Normal file
47
rma_purchase/README.rst
Normal file
@@ -0,0 +1,47 @@
|
||||
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg
|
||||
:alt: License LGPL-3
|
||||
|
||||
============
|
||||
RMA Purchase
|
||||
============
|
||||
|
||||
This modules extend the RMA functionality allowing to use Purchase Orders as
|
||||
a RMA source.
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
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
|
||||
===========
|
||||
|
||||
Bugs are tracked on `GitHub Issues
|
||||
<https://github.com/Eficent/stock-rma/issues>`_. In case of trouble, please
|
||||
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
|
||||
=======
|
||||
|
||||
Contributors
|
||||
------------
|
||||
|
||||
* Jordi Ballester Alomar <jordi.ballester@eficent.com>
|
||||
* Aaron Henriquez <ahenriquez@eficent.com>
|
||||
* Lois Rilo <lois.rilo@eficent.com>
|
||||
* Bhavesh Odedra <bodedra@opensourceintegrators.com>
|
||||
* Serpent Consulting Services Pvt. Ltd. <support@serpentcs.com>
|
||||
|
||||
Maintainer
|
||||
----------
|
||||
|
||||
This module is maintained by Eficent.
|
||||
5
rma_purchase/__init__.py
Normal file
5
rma_purchase/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
# © 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from . import models
|
||||
from . import wizards
|
||||
23
rma_purchase/__manifest__.py
Normal file
23
rma_purchase/__manifest__.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# © 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
{
|
||||
'name': 'RMA Purchase',
|
||||
'version': '12.0.1.0.0',
|
||||
'category': 'RMA',
|
||||
'summary': 'RMA from PO',
|
||||
'license': 'LGPL-3',
|
||||
'author': 'Eficent, Odoo Community Association (OCA)',
|
||||
'website': 'http://www.github.com/OCA/rma',
|
||||
'depends': ['rma_account', 'purchase'],
|
||||
'data': [
|
||||
'wizards/rma_order_line_make_purchase_order_view.xml',
|
||||
'security/ir.model.access.csv',
|
||||
'views/rma_operation_view.xml',
|
||||
'views/rma_order_view.xml',
|
||||
'views/rma_order_line_view.xml',
|
||||
'wizards/rma_add_purchase.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'auto_install': True,
|
||||
}
|
||||
7
rma_purchase/models/__init__.py
Normal file
7
rma_purchase/models/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from . import rma_order
|
||||
from . import rma_order_line
|
||||
from . import purchase_order
|
||||
from . import purchase_order_line
|
||||
from . import rma_operation
|
||||
26
rma_purchase/models/purchase_order.py
Normal file
26
rma_purchase/models/purchase_order.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# 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 odoo import api, models
|
||||
|
||||
|
||||
class PurchaseOrder(models.Model):
|
||||
_inherit = "purchase.order"
|
||||
|
||||
@api.model
|
||||
def new(self, vals):
|
||||
"""Allows to propose a line based on the RMA information."""
|
||||
res = super(PurchaseOrder, self).new(vals)
|
||||
rma_line_id = self.env.context.get('rma_line_id')
|
||||
if rma_line_id:
|
||||
rma_line = self.env['rma.order.line'].browse(rma_line_id)
|
||||
line = self.env['purchase.order.line'].new({
|
||||
'product_id': rma_line.product_id.id,
|
||||
})
|
||||
line.onchange_product_id()
|
||||
line.update({
|
||||
'product_qty': rma_line.qty_to_purchase,
|
||||
'product_uom': rma_line.uom_id.id,
|
||||
})
|
||||
res.order_line = line
|
||||
return res
|
||||
59
rma_purchase/models/purchase_order_line.py
Normal file
59
rma_purchase/models/purchase_order_line.py
Normal file
@@ -0,0 +1,59 @@
|
||||
# Copyright 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
|
||||
|
||||
|
||||
class PurchaseOrderLine(models.Model):
|
||||
_inherit = "purchase.order.line"
|
||||
|
||||
rma_line_id = fields.Many2one(
|
||||
comodel_name='rma.order.line', string='RMA',
|
||||
)
|
||||
|
||||
@api.model
|
||||
def name_search(self, name='', args=None, operator='ilike', limit=100):
|
||||
"""Allows to search by PO reference."""
|
||||
if not args:
|
||||
args = []
|
||||
args += ['|',
|
||||
(self._rec_name, operator, name),
|
||||
('order_id.name', operator, name)]
|
||||
return super(PurchaseOrderLine, self).name_search(
|
||||
name=name, args=args, operator=operator, limit=limit)
|
||||
|
||||
@api.model
|
||||
def _name_search(self, name='', args=None, operator='ilike',
|
||||
limit=100, name_get_uid=None):
|
||||
"""Typed text is cleared here for better extensibility."""
|
||||
return super(PurchaseOrderLine, self)._name_search(
|
||||
name='', args=args, operator=operator, limit=limit,
|
||||
name_get_uid=name_get_uid)
|
||||
|
||||
@api.multi
|
||||
def name_get(self):
|
||||
res = []
|
||||
if self.env.context.get('rma'):
|
||||
for purchase in self:
|
||||
invoices = self.env['account.invoice.line'].search(
|
||||
[('purchase_line_id', '=', purchase.id)])
|
||||
if purchase.order_id.name:
|
||||
res.append((purchase.id, "%s %s %s qty:%s" % (
|
||||
purchase.order_id.name,
|
||||
" ".join(str(x) for x in [
|
||||
inv.number for inv in invoices.mapped(
|
||||
'invoice_id')]),
|
||||
purchase.product_id.name, purchase.product_qty)))
|
||||
else:
|
||||
res.append(
|
||||
super(PurchaseOrderLine, purchase).name_get()[0])
|
||||
return res
|
||||
else:
|
||||
return super(PurchaseOrderLine, self).name_get()
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
rma_line_id = self.env.context.get('rma_line_id')
|
||||
if rma_line_id:
|
||||
vals['rma_line_id'] = rma_line_id
|
||||
return super(PurchaseOrderLine, self).create(vals)
|
||||
24
rma_purchase/models/rma_operation.py
Normal file
24
rma_purchase/models/rma_operation.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# Copyright 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 api, fields, models, _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class RmaOperation(models.Model):
|
||||
_inherit = 'rma.operation'
|
||||
|
||||
purchase_policy = fields.Selection(
|
||||
selection=[('no', 'Not required'),
|
||||
('ordered', 'Based on Ordered Quantities'),
|
||||
('delivered', 'Based on Delivered Quantities')],
|
||||
string="Purchase Policy", default='no',
|
||||
)
|
||||
|
||||
@api.multi
|
||||
@api.constrains('purchase_policy')
|
||||
def _check_purchase_policy(self):
|
||||
if self.filtered(
|
||||
lambda r: r.purchase_policy != 'no' and r.type != 'supplier'):
|
||||
raise ValidationError(_(
|
||||
'Purchase Policy can only apply to supplier operations'))
|
||||
54
rma_purchase/models/rma_order.py
Normal file
54
rma_purchase/models/rma_order.py
Normal file
@@ -0,0 +1,54 @@
|
||||
# © 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
|
||||
|
||||
|
||||
class RmaOrder(models.Model):
|
||||
_inherit = "rma.order"
|
||||
|
||||
@api.multi
|
||||
def _compute_po_count(self):
|
||||
for rec in self:
|
||||
po_count = 0
|
||||
rma_line_po = []
|
||||
for line in rec.rma_line_ids:
|
||||
rma_line_po += self.env['purchase.order'].search(
|
||||
[('origin', '=', line.name)]).ids
|
||||
if rma_line_po:
|
||||
po_count = len(list(set(rma_line_po)))
|
||||
rec.po_count = po_count
|
||||
|
||||
@api.multi
|
||||
@api.depends('rma_line_ids')
|
||||
def _compute_origin_po_count(self):
|
||||
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')
|
||||
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]
|
||||
po_ids = self.env['purchase.order'].search(
|
||||
[('origin', '=', self.name)]).ids
|
||||
for line in self.rma_line_ids:
|
||||
po_ids += self.env['purchase.order'].search(
|
||||
[('origin', '=', line.name)]).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]
|
||||
po_ids = self.mapped(
|
||||
'rma_line_ids.purchase_order_line_id.order_id').ids
|
||||
result['domain'] = [('id', 'in', po_ids)]
|
||||
return result
|
||||
203
rma_purchase/models/rma_order_line.py
Normal file
203
rma_purchase/models/rma_order_line.py
Normal file
@@ -0,0 +1,203 @@
|
||||
# © 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 ValidationError
|
||||
from odoo.addons import decimal_precision as dp
|
||||
|
||||
|
||||
class RmaOrderLine(models.Model):
|
||||
_inherit = "rma.order.line"
|
||||
|
||||
@api.multi
|
||||
def _compute_purchase_count(self):
|
||||
for rec in self:
|
||||
purchase_line_count = self.env['purchase.order.line'].search(
|
||||
[('rma_line_id', '=', rec.id)])
|
||||
rec.purchase_count = len(purchase_line_count.mapped('order_id'))
|
||||
|
||||
@api.multi
|
||||
def _compute_purchase_order_lines(self):
|
||||
for rec in self:
|
||||
purchase_list = []
|
||||
for line in self.env['purchase.order.line'].search(
|
||||
[('rma_line_id', '=', rec.id)]):
|
||||
purchase_list.append(line.id)
|
||||
rec.purchase_order_line_ids = [(6, 0, purchase_list)]
|
||||
|
||||
@api.multi
|
||||
def _compute_qty_purchase(self):
|
||||
for rec in self:
|
||||
rec.qty_purchased = rec._get_rma_purchased_qty()
|
||||
if rec.purchase_policy == 'ordered':
|
||||
rec.qty_to_purchase = rec.product_qty - rec.qty_purchased
|
||||
elif rec.purchase_policy == 'delivered':
|
||||
rec.qty_to_purchase = rec.qty_delivered - rec.qty_purchased
|
||||
else:
|
||||
rec.qty_to_purchase = 0.0
|
||||
|
||||
purchase_count = fields.Integer(
|
||||
compute='_compute_purchase_count', string='# of Purchases',
|
||||
)
|
||||
purchase_order_line_id = fields.Many2one(
|
||||
comodel_name='purchase.order.line', string='Originating Purchase Line',
|
||||
ondelete='restrict',
|
||||
readonly=True, states={'draft': [('readonly', False)]},
|
||||
)
|
||||
purchase_id = fields.Many2one(
|
||||
string="Source Purchase Order",
|
||||
related='purchase_order_line_id.order_id',
|
||||
readonly=True,
|
||||
)
|
||||
purchase_order_line_ids = fields.Many2many(
|
||||
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='_compute_purchase_order_lines',
|
||||
)
|
||||
purchase_policy = fields.Selection(
|
||||
selection=[('no', 'Not required'),
|
||||
('ordered', 'Based on Ordered Quantities'),
|
||||
('delivered', 'Based on Delivered Quantities')],
|
||||
string="Purchase Policy", default='no',
|
||||
required=True,
|
||||
)
|
||||
manual_purchase_line_ids = fields.One2many(
|
||||
comodel_name='purchase.order.line',
|
||||
inverse_name='rma_line_id',
|
||||
string='Manual Purchase Order Lines',
|
||||
readonly=True, copy=False)
|
||||
qty_to_purchase = fields.Float(
|
||||
string='Qty To Purchase', copy=False,
|
||||
digits=dp.get_precision('Product Unit of Measure'),
|
||||
readonly=True, compute='_compute_qty_purchase'
|
||||
)
|
||||
qty_purchased = fields.Float(
|
||||
string='Qty Purchased', copy=False,
|
||||
digits=dp.get_precision('Product Unit of Measure'),
|
||||
readonly=True, compute='_compute_qty_purchase'
|
||||
)
|
||||
|
||||
@api.onchange('product_id', 'partner_id')
|
||||
def _onchange_product_id(self):
|
||||
"""Domain for purchase_order_line_id is computed here to make
|
||||
it dynamic."""
|
||||
res = super(RmaOrderLine, self)._onchange_product_id()
|
||||
if not res.get('domain'):
|
||||
res['domain'] = {}
|
||||
domain = [
|
||||
'|',
|
||||
('order_id.partner_id', '=', self.partner_id.id),
|
||||
('order_id.partner_id', 'child_of', self.partner_id.id)]
|
||||
if self.product_id:
|
||||
domain.append(('product_id', '=', self.product_id.id))
|
||||
res['domain']['purchase_order_line_id'] = domain
|
||||
return res
|
||||
|
||||
@api.onchange('operation_id')
|
||||
def _onchange_operation_id(self):
|
||||
res = super(RmaOrderLine, self)._onchange_operation_id()
|
||||
if self.operation_id:
|
||||
self.purchase_policy = self.operation_id.purchase_policy or 'no'
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
def _prepare_rma_line_from_po_line(self, line):
|
||||
self.ensure_one()
|
||||
if not self.type:
|
||||
self.type = self._get_default_type()
|
||||
if self.type == 'customer':
|
||||
operation = line.product_id.rma_customer_operation_id or \
|
||||
line.product_id.categ_id.rma_customer_operation_id
|
||||
else:
|
||||
operation = line.product_id.rma_supplier_operation_id or \
|
||||
line.product_id.categ_id.rma_supplier_operation_id
|
||||
if not operation:
|
||||
operation = self.env['rma.operation'].search(
|
||||
[('type', '=', self.type)], limit=1)
|
||||
if not operation:
|
||||
raise ValidationError(_("Please define an operation first"))
|
||||
|
||||
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 a rma route."))
|
||||
|
||||
if not operation.in_warehouse_id or not operation.out_warehouse_id:
|
||||
warehouse = self.env['stock.warehouse'].search(
|
||||
[('company_id', '=', self.company_id.id),
|
||||
('lot_rma_id', '!=', False)], limit=1)
|
||||
if not warehouse:
|
||||
raise ValidationError(_(
|
||||
"Please define a warehouse with a default rma location."))
|
||||
|
||||
data = {
|
||||
'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._convert(
|
||||
line.price_unit, line.currency_id,
|
||||
self.env.user.company_id, fields.Date.today(), round=False),
|
||||
'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,
|
||||
'currency_id': line.currency_id.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,
|
||||
'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.onchange('purchase_order_line_id')
|
||||
def _onchange_purchase_order_line_id(self):
|
||||
if not self.purchase_order_line_id:
|
||||
return
|
||||
data = self._prepare_rma_line_from_po_line(
|
||||
self.purchase_order_line_id)
|
||||
self.update(data)
|
||||
self._remove_other_data_origin('purchase_order_line_id')
|
||||
|
||||
@api.multi
|
||||
@api.constrains('purchase_order_line_id', 'partner_id')
|
||||
def _check_purchase_partner(self):
|
||||
for rec in self:
|
||||
if (rec.purchase_order_line_id and
|
||||
rec.purchase_order_line_id.order_id.partner_id !=
|
||||
rec.partner_id):
|
||||
raise ValidationError(_(
|
||||
"RMA customer and originating purchase line customer "
|
||||
"doesn't match."))
|
||||
|
||||
@api.multi
|
||||
def _remove_other_data_origin(self, exception):
|
||||
res = super(RmaOrderLine, self)._remove_other_data_origin(exception)
|
||||
if not exception == 'purchase_order_line_id':
|
||||
self.purchase_order_line_id = False
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
def action_view_purchase_order(self):
|
||||
action = self.env.ref('purchase.purchase_rfq')
|
||||
result = action.read()[0]
|
||||
orders = self.mapped('purchase_order_line_ids.order_id')
|
||||
result['domain'] = [('id', 'in', orders.ids)]
|
||||
return result
|
||||
|
||||
@api.multi
|
||||
def _get_rma_purchased_qty(self):
|
||||
self.ensure_one()
|
||||
qty = 0.0
|
||||
if self.type == 'customer':
|
||||
return qty
|
||||
for line in self.purchase_order_line_ids.filtered(
|
||||
lambda p: p.state not in ('draft', 'sent', 'cancel')):
|
||||
qty += self.uom_id._compute_quantity(
|
||||
line.product_qty, line.product_uom)
|
||||
return qty
|
||||
3
rma_purchase/security/ir.model.access.csv
Executable file
3
rma_purchase/security/ir.model.access.csv
Executable file
@@ -0,0 +1,3 @@
|
||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_purchase_order_supplier_user,access_purchase_order,purchase.model_purchase_order,rma.group_rma_supplier_user,1,0,0,0
|
||||
access_purchase_order_line_supplier_user,access_purchase_order_line,purchase.model_purchase_order_line,rma.group_rma_supplier_user,1,0,0,0
|
||||
|
4
rma_purchase/tests/__init__.py
Normal file
4
rma_purchase/tests/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
# Copyright 2018 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from . import test_rma_purchase
|
||||
93
rma_purchase/tests/test_rma_purchase.py
Normal file
93
rma_purchase/tests/test_rma_purchase.py
Normal file
@@ -0,0 +1,93 @@
|
||||
# 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 odoo.tests import common
|
||||
from odoo.fields import Datetime
|
||||
|
||||
|
||||
class TestRmaPurchase(common.TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestRmaPurchase, self).setUp()
|
||||
|
||||
self.rma_obj = self.env['rma.order']
|
||||
self.rma_line_obj = self.env['rma.order.line']
|
||||
self.rma_op_obj = self.env['rma.operation']
|
||||
self.rma_add_purchase_wiz = self.env['rma_add_purchase']
|
||||
self.po_obj = self.env['purchase.order']
|
||||
self.pol_obj = self.env['purchase.order.line']
|
||||
self.product_obj = self.env['product.product']
|
||||
self.partner_obj = self.env['res.partner']
|
||||
|
||||
self.rma_route_cust = self.env.ref('rma.route_rma_customer')
|
||||
|
||||
# Create supplier
|
||||
supplier1 = self.partner_obj.create({'name': 'Supplier 1'})
|
||||
|
||||
# Create products
|
||||
self.product_1 = self.product_obj.create({
|
||||
'name': 'Test Product 1',
|
||||
'type': 'product',
|
||||
})
|
||||
self.product_2 = self.product_obj.create({
|
||||
'name': 'Test Product 2',
|
||||
'type': 'product',
|
||||
})
|
||||
|
||||
# Create PO:
|
||||
self.po = self.po_obj.create({
|
||||
'partner_id': supplier1.id,
|
||||
})
|
||||
self.pol_1 = self.pol_obj.create({
|
||||
'name': self.product_1.name,
|
||||
'order_id': self.po.id,
|
||||
'product_id': self.product_1.id,
|
||||
'product_qty': 20.0,
|
||||
'product_uom': self.product_1.uom_id.id,
|
||||
'price_unit': 100.0,
|
||||
'date_planned': Datetime.now(),
|
||||
})
|
||||
self.pol_2 = self.pol_obj.create({
|
||||
'name': self.product_2.name,
|
||||
'order_id': self.po.id,
|
||||
'product_id': self.product_2.id,
|
||||
'product_qty': 18.0,
|
||||
'product_uom': self.product_2.uom_id.id,
|
||||
'price_unit': 150.0,
|
||||
'date_planned': Datetime.now(),
|
||||
})
|
||||
|
||||
# Create RMA group:
|
||||
self.rma_group = self.rma_obj.create({
|
||||
'partner_id': supplier1.id,
|
||||
'type': 'supplier',
|
||||
})
|
||||
|
||||
def test_01_add_from_purchase_order(self):
|
||||
"""Test wizard to create supplier RMA from Purchase Orders."""
|
||||
self.assertEqual(self.rma_group.origin_po_count, 0)
|
||||
add_purchase = self.rma_add_purchase_wiz.with_context({
|
||||
'supplier': True,
|
||||
'active_ids': self.rma_group.id,
|
||||
'active_model': 'rma.order',
|
||||
}).create({
|
||||
'purchase_id': self.po.id,
|
||||
'purchase_line_ids': [(6, 0, self.po.order_line.ids)],
|
||||
})
|
||||
add_purchase.add_lines()
|
||||
self.assertEqual(len(self.rma_group.rma_line_ids), 2)
|
||||
for t in self.rma_group.rma_line_ids.mapped('type'):
|
||||
self.assertEqual(t, 'supplier')
|
||||
self.assertEqual(self.rma_group.origin_po_count, 1)
|
||||
|
||||
def test_02_fill_rma_from_po_line(self):
|
||||
"""Test filling a RMA (line) from a Purchase Order line."""
|
||||
rma = self.rma_line_obj.new({
|
||||
'partner_id': self.po.partner_id.id,
|
||||
'purchase_order_line_id': self.pol_1.id,
|
||||
'type': 'supplier',
|
||||
})
|
||||
self.assertFalse(rma.product_id)
|
||||
rma._onchange_purchase_order_line_id()
|
||||
self.assertEqual(rma.product_id, self.product_1)
|
||||
self.assertEqual(rma.product_qty, 20.0)
|
||||
28
rma_purchase/views/rma_operation_view.xml
Normal file
28
rma_purchase/views/rma_operation_view.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- Copyright 2018 Eficent Business and IT Consulting Services S.L.
|
||||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) -->
|
||||
<odoo>
|
||||
|
||||
<record id="rma_operation_tree" model="ir.ui.view">
|
||||
<field name="name">rma.operation.tree - rma_purchase</field>
|
||||
<field name="model">rma.operation</field>
|
||||
<field name="inherit_id" ref="rma.rma_operation_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="delivery_policy" position="after">
|
||||
<field name="purchase_policy"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="rma_operation_form" model="ir.ui.view">
|
||||
<field name="name">rma.operation.form - rma_purchase</field>
|
||||
<field name="model">rma.operation</field>
|
||||
<field name="inherit_id" ref="rma.rma_operation_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="delivery_policy" position="after">
|
||||
<field name="purchase_policy"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
69
rma_purchase/views/rma_order_line_view.xml
Normal file
69
rma_purchase/views/rma_order_line_view.xml
Normal file
@@ -0,0 +1,69 @@
|
||||
<?xml version="1.0"?>
|
||||
<odoo>
|
||||
|
||||
<record id="action_rma_line_purchase" model="ir.actions.act_window">
|
||||
<field name="name">Purchase Order</field>
|
||||
<field name="res_model">purchase.order</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="target">current</field>
|
||||
<field name="view_mode">form,tree</field>
|
||||
</record>
|
||||
|
||||
<record id="view_rma_line_supplier_button_sale_form" model="ir.ui.view">
|
||||
<field name="name">rma.order.line.supplier.form</field>
|
||||
<field name="model">rma.order.line</field>
|
||||
<field name="inherit_id" ref="rma.view_rma_line_supplier_button_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<header position="inside">
|
||||
<button name="%(action_rma_order_line_make_purchase_order)d" states="approved"
|
||||
string="Create Purchase Order" class="oe_highlight"
|
||||
context="{'rma_line_id': active_id, 'default_partner_id': partner_id}"
|
||||
type="action"/>
|
||||
</header>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_rma_line_form" model="ir.ui.view">
|
||||
<field name="name">rma.order.line.supplier.form</field>
|
||||
<field name="model">rma.order.line</field>
|
||||
<field name="inherit_id" ref="rma.view_rma_line_supplier_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<div name='button_box' position="inside">
|
||||
<button type="object" name="action_view_purchase_order"
|
||||
class="oe_stat_button"
|
||||
icon="fa-shopping-cart"
|
||||
groups="purchase.group_purchase_user">
|
||||
<field name="purchase_count" widget="statinfo"
|
||||
string="Purchase Orders"/>
|
||||
</button>
|
||||
</div>
|
||||
<group name="main_info" position="inside">
|
||||
<field name="purchase_order_line_id"
|
||||
options="{'no_create': True}"
|
||||
context="{'rma': True}"
|
||||
domain="['|',
|
||||
('order_id.partner_id', '=', partner_id),
|
||||
('order_id.partner_id', 'child_of', partner_id)]"/>
|
||||
</group>
|
||||
<group name="quantities" position="inside">
|
||||
<group>
|
||||
<field name="qty_to_purchase"/>
|
||||
<field name="qty_purchased"/>
|
||||
</group>
|
||||
</group>
|
||||
<field name="delivery_policy" position="after">
|
||||
<field name="purchase_policy"/>
|
||||
</field>
|
||||
<field name="origin" position="after">
|
||||
<field name="purchase_id"
|
||||
attrs="{'invisible': [('purchase_order_line_id', '=', False)]}"/>
|
||||
</field>
|
||||
<notebook position="inside">
|
||||
<page name="purchase" string="Purchase Lines">
|
||||
<field name="purchase_order_line_ids" nolabel="1"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
29
rma_purchase/views/rma_order_view.xml
Normal file
29
rma_purchase/views/rma_order_view.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0"?>
|
||||
<odoo>
|
||||
|
||||
<record id="view_rma_supplier_form" model="ir.ui.view">
|
||||
<field name="name">rma.order.supplier.form</field>
|
||||
<field name="model">rma.order</field>
|
||||
<field name="inherit_id" ref="rma.view_rma_supplier_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<div name='button_box' position="inside">
|
||||
<button type="object" name="action_view_purchase_order"
|
||||
class="oe_stat_button"
|
||||
icon="fa-shopping-cart"
|
||||
groups="purchase.group_purchase_user">
|
||||
<field name="po_count" widget="statinfo"
|
||||
string="Purchase Orders"/>
|
||||
</button>
|
||||
<button type="object"
|
||||
name="action_view_origin_purchase_order"
|
||||
class="oe_stat_button"
|
||||
icon="fa-shopping-cart"
|
||||
groups="purchase.group_purchase_user">
|
||||
<field name="origin_po_count" widget="statinfo"
|
||||
string="Origin PO"/>
|
||||
</button>
|
||||
</div>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
6
rma_purchase/wizards/__init__.py
Normal file
6
rma_purchase/wizards/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
# © 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from . import rma_make_picking
|
||||
from . import rma_add_purchase
|
||||
from . import rma_order_line_make_purchase_order
|
||||
116
rma_purchase/wizards/rma_add_purchase.py
Normal file
116
rma_purchase/wizards/rma_add_purchase.py
Normal file
@@ -0,0 +1,116 @@
|
||||
# © 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 ValidationError
|
||||
|
||||
|
||||
class RmaAddPurchase(models.TransientModel):
|
||||
_name = 'rma_add_purchase'
|
||||
_description = 'Wizard to add rma lines'
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
res = super(RmaAddPurchase, self).default_get(fields)
|
||||
rma_obj = self.env['rma.order']
|
||||
rma_id = self.env.context['active_ids'] or []
|
||||
active_model = self.env.context['active_model']
|
||||
if not rma_id:
|
||||
return res
|
||||
assert active_model == 'rma.order', 'Bad context propagation'
|
||||
|
||||
rma = rma_obj.browse(rma_id)
|
||||
res['rma_id'] = rma.id
|
||||
res['partner_id'] = rma.partner_id.id
|
||||
res['purchase_id'] = False
|
||||
res['purchase_line_ids'] = False
|
||||
return res
|
||||
|
||||
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(
|
||||
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'):
|
||||
operation = line.product_id.rma_customer_operation_id or \
|
||||
line.product_id.categ_id.rma_customer_operation_id
|
||||
else:
|
||||
operation = line.product_id.rma_supplier_operation_id or \
|
||||
line.product_id.categ_id.rma_supplier_operation_id
|
||||
if not operation:
|
||||
operation = self.env['rma.operation'].search(
|
||||
[('type', '=', self.rma_id.type)], limit=1)
|
||||
if not operation:
|
||||
raise ValidationError(_("Please define an operation first"))
|
||||
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 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 = {
|
||||
'partner_id': self.partner_id.id,
|
||||
'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._convert(
|
||||
line.price_unit, line.currency_id,
|
||||
self.env.user.company_id, fields.Date.today(), 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
|
||||
operation.in_warehouse_id.lot_rma_id.id or
|
||||
warehouse.lot_rma_id.id),
|
||||
'refund_policy': operation.refund_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
|
||||
def _get_rma_data(self):
|
||||
data = {
|
||||
'date_rma': fields.Datetime.now(),
|
||||
}
|
||||
return data
|
||||
|
||||
@api.model
|
||||
def _get_existing_purchase_lines(self):
|
||||
existing_purchase_lines = []
|
||||
for rma_line in self.rma_id.rma_line_ids:
|
||||
existing_purchase_lines.append(rma_line.purchase_order_line_id)
|
||||
return existing_purchase_lines
|
||||
|
||||
@api.multi
|
||||
def add_lines(self):
|
||||
rma_line_obj = self.env['rma.order.line']
|
||||
existing_purchase_lines = self._get_existing_purchase_lines()
|
||||
for line in self.purchase_line_ids:
|
||||
# Load a PO line only once
|
||||
if line not in existing_purchase_lines:
|
||||
data = self._prepare_rma_line_from_po_line(line)
|
||||
rma_line_obj.create(data)
|
||||
rma = self.rma_id
|
||||
data_rma = self._get_rma_data()
|
||||
rma.write(data_rma)
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
74
rma_purchase/wizards/rma_add_purchase.xml
Normal file
74
rma_purchase/wizards/rma_add_purchase.xml
Normal file
@@ -0,0 +1,74 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<odoo>
|
||||
<record id="view_rma_add_purchase" model="ir.ui.view">
|
||||
<field name="name">rma.add.purchase</field>
|
||||
<field name="model">rma_add_purchase</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Select Purchase Order from customer">
|
||||
<group>
|
||||
<field name="partner_id"
|
||||
domain="[('customer','=',True)]"
|
||||
string="Customer"/>
|
||||
</group>
|
||||
<separator string="Select Purchase Order from customer"/>
|
||||
<group>
|
||||
<field name="purchase_id"
|
||||
domain="[
|
||||
('partner_id','=',partner_id), (('state','not in',['draft','cancel']))]"
|
||||
context="{'partner_id': partner_id}"/>
|
||||
</group>
|
||||
<separator string="Select Purchase Order Lines to Add"/>
|
||||
<field name="purchase_line_ids"
|
||||
domain="[('order_id', '=', purchase_id)]"
|
||||
string="Purchase Order Lines">
|
||||
<tree string="Purchase Order Lines">
|
||||
<field name="order_id"/>
|
||||
<field name="name"/>
|
||||
<field name="partner_id" string="Vendor" />
|
||||
<field name="product_id"/>
|
||||
<field name="price_unit"/>
|
||||
<field name="product_qty"/>
|
||||
<field name="product_uom" groups="uom.group_uom"/>
|
||||
<field name="price_subtotal" widget="monetary"/>
|
||||
<field name="date_planned" widget="date"/>
|
||||
</tree>
|
||||
</field>
|
||||
<footer>
|
||||
<button
|
||||
string="Confirm"
|
||||
name="add_lines" type="object"
|
||||
class="oe_highlight"/>
|
||||
or
|
||||
<button name="action_cancel"
|
||||
string="Cancel" class="oe_link" special="cancel"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_rma_add_purchase" model="ir.actions.act_window">
|
||||
<field name="name">Add Purchase Order</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">rma_add_purchase</field>
|
||||
<field name="src_model">rma.order</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
<field name="view_id" ref="view_rma_add_purchase"/>
|
||||
<field name="groups_id" eval="[(4, ref('rma.group_rma_customer_user')), (4, ref('rma.group_rma_customer_user'))]"/>
|
||||
</record>
|
||||
|
||||
<record id="view_rma_add_purchase_button_form" model="ir.ui.view">
|
||||
<field name="name">rma.order.line.supplier.form</field>
|
||||
<field name="model">rma.order</field>
|
||||
<field name="inherit_id" ref="rma.view_rma_supplier_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//header" position="inside">
|
||||
<button name="%(action_rma_add_purchase)d"
|
||||
string="Add From Purchase Order"
|
||||
type="action"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
38
rma_purchase/wizards/rma_make_picking.py
Normal file
38
rma_purchase/wizards/rma_make_picking.py
Normal file
@@ -0,0 +1,38 @@
|
||||
# © 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
|
||||
|
||||
|
||||
class RmaMakePicking(models.TransientModel):
|
||||
_inherit = 'rma_make_picking.wizard'
|
||||
|
||||
@api.returns('rma.order.line')
|
||||
def _prepare_item(self, line):
|
||||
res = super(RmaMakePicking, self)._prepare_item(line)
|
||||
res['purchase_order_line_id'] = line.purchase_order_line_id.id
|
||||
return res
|
||||
|
||||
@api.model
|
||||
def _get_action(self, pickings, procurements):
|
||||
po_list = []
|
||||
for procurement in procurements:
|
||||
if procurement.purchase_id and \
|
||||
procurement.purchase_id.id:
|
||||
po_list.append(procurement.purchase_id.id)
|
||||
if len(po_list):
|
||||
action = self.env.ref('purchase.purchase_rfq')
|
||||
result = action.read()[0]
|
||||
result['domain'] = [('id', 'in', po_list)]
|
||||
return result
|
||||
else:
|
||||
action = super(RmaMakePicking, self)._get_action(pickings,
|
||||
procurements)
|
||||
return action
|
||||
|
||||
|
||||
class RmaMakePickingItem(models.TransientModel):
|
||||
_inherit = "rma_make_picking.wizard.item"
|
||||
|
||||
purchase_order_line_id = fields.Many2one('purchase.order.line',
|
||||
string='Purchase Line')
|
||||
143
rma_purchase/wizards/rma_order_line_make_purchase_order.py
Normal file
143
rma_purchase/wizards/rma_order_line_make_purchase_order.py
Normal file
@@ -0,0 +1,143 @@
|
||||
# Copyright 2018 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0).
|
||||
|
||||
import odoo.addons.decimal_precision as dp
|
||||
from odoo import fields, models, api, _, exceptions
|
||||
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT as DF
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class RmaLineMakePurchaseOrder(models.TransientModel):
|
||||
_name = "rma.order.line.make.purchase.order"
|
||||
_description = "Make Purchases Order from RMA Line"
|
||||
|
||||
partner_id = fields.Many2one(
|
||||
comodel_name='res.partner', string='Supplier', required=False,
|
||||
domain=[('supplier', '=', True)], readonly=1)
|
||||
item_ids = fields.One2many(
|
||||
comodel_name='rma.order.line.make.purchase.order.item',
|
||||
inverse_name='wiz_id', string='Items')
|
||||
purchase_order_id = fields.Many2one(
|
||||
comodel_name='purchase.order', string='Purchases Order',
|
||||
required=False, domain=[('state', '=', 'draft')])
|
||||
|
||||
@api.model
|
||||
def _prepare_item(self, line):
|
||||
return {
|
||||
'line_id': line.id,
|
||||
'rma_line_id': line.id,
|
||||
'product_id': line.product_id.id,
|
||||
'name': line.product_id.name,
|
||||
'product_qty': line.qty_to_purchase,
|
||||
'rma_id': line.rma_id.id,
|
||||
'product_uom_id': line.uom_id.id,
|
||||
}
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
res = super(RmaLineMakePurchaseOrder, self).default_get(
|
||||
fields)
|
||||
rma_line_obj = self.env['rma.order.line']
|
||||
rma_line_ids = self.env.context['active_ids'] or []
|
||||
active_model = self.env.context['active_model']
|
||||
|
||||
if not rma_line_ids:
|
||||
return res
|
||||
assert active_model == 'rma.order.line', 'Bad context propagation'
|
||||
|
||||
items = []
|
||||
lines = rma_line_obj.browse(rma_line_ids)
|
||||
for line in lines:
|
||||
items.append([0, 0, self._prepare_item(line)])
|
||||
suppliers = lines.mapped('partner_id')
|
||||
if len(suppliers) == 1:
|
||||
res['partner_id'] = suppliers.id
|
||||
else:
|
||||
raise exceptions.Warning(
|
||||
_('Only RMA lines from the same partner can be processed at '
|
||||
'the same time'))
|
||||
res['item_ids'] = items
|
||||
return res
|
||||
|
||||
@api.model
|
||||
def _prepare_purchase_order(self, item):
|
||||
if not self.partner_id:
|
||||
raise exceptions.Warning(
|
||||
_('Enter a supplier.'))
|
||||
supplier = self.partner_id
|
||||
data = {
|
||||
'origin': '',
|
||||
'partner_id': supplier.id,
|
||||
'company_id': item.line_id.company_id.id,
|
||||
}
|
||||
return data
|
||||
|
||||
@api.model
|
||||
def _prepare_purchase_order_line(self, po, item):
|
||||
product = item.product_id
|
||||
vals = {
|
||||
'name': product.name,
|
||||
'order_id': po.id,
|
||||
'product_id': product.id,
|
||||
'price_unit': item.line_id.price_unit,
|
||||
'date_planned': datetime.today().strftime(DF),
|
||||
'product_uom': product.uom_po_id.id,
|
||||
'product_qty': item.product_qty,
|
||||
'rma_line_id': item.line_id.id
|
||||
}
|
||||
if item.free_of_charge:
|
||||
vals['price_unit'] = 0.0
|
||||
return vals
|
||||
|
||||
@api.multi
|
||||
def create_purchase_order(self):
|
||||
res = []
|
||||
purchase_obj = self.env['purchase.order']
|
||||
po_line_obj = self.env['purchase.order.line']
|
||||
|
||||
for item in self.item_ids:
|
||||
if item.product_qty <= 0.0:
|
||||
raise exceptions.Warning(
|
||||
_('Enter a positive quantity.'))
|
||||
|
||||
purchase = self.purchase_order_id
|
||||
if not purchase:
|
||||
po_data = self._prepare_purchase_order(item)
|
||||
purchase = purchase_obj.create(po_data)
|
||||
|
||||
po_line_data = self._prepare_purchase_order_line(purchase, item)
|
||||
po_line_obj.create(po_line_data)
|
||||
res.append(purchase.id)
|
||||
|
||||
return {
|
||||
'domain': "[('id','in', ["+','.join(map(str, res))+"])]",
|
||||
'name': _('Request for Quotation'),
|
||||
'view_type': 'form',
|
||||
'view_mode': 'tree,form',
|
||||
'res_model': 'purchase.order',
|
||||
'view_id': False,
|
||||
'context': False,
|
||||
'type': 'ir.actions.act_window'
|
||||
}
|
||||
|
||||
|
||||
class RmaLineMakePurchaseOrderItem(models.TransientModel):
|
||||
_name = "rma.order.line.make.purchase.order.item"
|
||||
_description = "RMA Line Make Purchase Order Item"
|
||||
|
||||
wiz_id = fields.Many2one(
|
||||
comodel_name='rma.order.line.make.purchase.order', string='Wizard')
|
||||
line_id = fields.Many2one(
|
||||
comodel_name='rma.order.line', string='RMA Line')
|
||||
rma_id = fields.Many2one(
|
||||
comodel_name='rma.order', related='line_id.rma_id',
|
||||
string='RMA Order')
|
||||
product_id = fields.Many2one(
|
||||
comodel_name='product.product', string='Product')
|
||||
name = fields.Char(string='Description')
|
||||
product_qty = fields.Float(
|
||||
string='Quantity to purchase',
|
||||
digits=dp.get_precision('Product Unit of Measure'),)
|
||||
product_uom_id = fields.Many2one(
|
||||
comodel_name='uom.uom', string='UoM')
|
||||
free_of_charge = fields.Boolean(string='Free of Charge')
|
||||
@@ -0,0 +1,61 @@
|
||||
<?xml version="1.0"?>
|
||||
<odoo>
|
||||
<record id="view_rma_order_line_make_purchase_order" model="ir.ui.view">
|
||||
<field name="name">RMA Line Make Purchase Order</field>
|
||||
<field name="model">rma.order.line.make.purchase.order</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Create Quotation" create="false" edit="false">
|
||||
<separator string="Existing Quotation to update:"/>
|
||||
<newline/>
|
||||
<group>
|
||||
<field name="purchase_order_id"
|
||||
domain="[('partner_id','=',partner_id)]"
|
||||
context="{'partner_id': partner_id}"/>
|
||||
</group>
|
||||
<newline/>
|
||||
<separator
|
||||
string="New Purchases Order details:"/>
|
||||
<newline/>
|
||||
<group>
|
||||
<field name="partner_id"/>
|
||||
</group>
|
||||
<newline/>
|
||||
<group>
|
||||
<field name="item_ids" nolabel="1" colspan="2">
|
||||
<tree string="Details" editable="bottom" create="false">
|
||||
<field name="line_id"
|
||||
options="{'no_open': true}"/>
|
||||
<field name="product_id"/>
|
||||
<field name="name"/>
|
||||
<field name="product_qty"/>
|
||||
<field name="product_uom_id"
|
||||
groups="uom.group_uom"/>
|
||||
<field name="free_of_charge"/>
|
||||
</tree>
|
||||
</field>
|
||||
</group>
|
||||
<newline/>
|
||||
<footer colspan="2">
|
||||
<button name="create_purchase_order"
|
||||
string="Create RFQ" type="object"
|
||||
class="oe_highlight"/>
|
||||
<button special="cancel" string="Cancel" class="oe_link"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_rma_order_line_make_purchase_order"
|
||||
model="ir.actions.act_window">
|
||||
<field name="name">Create RFQ</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">rma.order.line.make.purchase.order</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="view_rma_order_line_make_purchase_order"/>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user