mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
init branch
This commit is contained in:
committed by
Chanakya Soni
parent
bddac377ff
commit
20ecbee99c
37
rma_purchase/README.rst
Normal file
37
rma_purchase/README.rst
Normal file
@@ -0,0 +1,37 @@
|
||||
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg
|
||||
:alt: License LGPL-3
|
||||
|
||||
RMA Purchase
|
||||
===========
|
||||
|
||||
Purchase as RMA source
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
select add_purchase_id to fill rma from RMA purchase
|
||||
|
||||
|
||||
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>
|
||||
|
||||
|
||||
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 @@
|
||||
# -*- 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 . import models
|
||||
from . import wizards
|
||||
20
rma_purchase/__openerp__.py
Normal file
20
rma_purchase/__openerp__.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# -*- 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)
|
||||
{
|
||||
'name': 'RMA Purchase',
|
||||
'version': '9.0.1.0.0',
|
||||
'category': 'RMA',
|
||||
'summary': 'RMA from PO',
|
||||
'description': """
|
||||
RMA from PO
|
||||
""",
|
||||
'author': 'Eficent',
|
||||
'website': 'http://www.github.com/OCA/rma',
|
||||
'depends': ['rma_account', 'purchase'],
|
||||
'data': ['views/rma_order_view.xml',
|
||||
'views/rma_order_line_view.xml',
|
||||
'wizards/rma_add_purchase.xml'],
|
||||
'installable': True,
|
||||
'auto_install': True,
|
||||
}
|
||||
5
rma_purchase/models/__init__.py
Normal file
5
rma_purchase/models/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
# -*- 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 . import rma_order
|
||||
from . import rma_order_line
|
||||
62
rma_purchase/models/rma_order.py
Normal file
62
rma_purchase/models/rma_order.py
Normal file
@@ -0,0 +1,62 @@
|
||||
# -*- 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 openerp import api, fields, models
|
||||
from openerp.addons import decimal_precision as dp
|
||||
from random import randint
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class RmaOrder(models.Model):
|
||||
_inherit = "rma.order"
|
||||
|
||||
@api.depends('rma_line_ids', 'rma_line_ids.procurement_ids')
|
||||
@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)))
|
||||
|
||||
@api.one
|
||||
def _compute_origin_po_count(self):
|
||||
po_list = []
|
||||
for rma_line in self.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)))
|
||||
|
||||
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)
|
||||
|
||||
@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)]
|
||||
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)]
|
||||
return result
|
||||
72
rma_purchase/models/rma_order_line.py
Normal file
72
rma_purchase/models/rma_order_line.py
Normal file
@@ -0,0 +1,72 @@
|
||||
# -*- 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 openerp import api, fields, models
|
||||
from openerp.addons import decimal_precision as dp
|
||||
from random import randint
|
||||
|
||||
|
||||
class RmaOrderLine(models.Model):
|
||||
_inherit = "rma.order.line"
|
||||
|
||||
@api.one
|
||||
def _compute_purchase_count(self):
|
||||
purchase_list = []
|
||||
for procurement_id in self.procurement_ids:
|
||||
if procurement_id.purchase_id and procurement_id.purchase_id.id:
|
||||
purchase_list.append(procurement_id.purchase_id.id)
|
||||
self.purchase_count = len(list(set(purchase_list)))
|
||||
|
||||
@api.one
|
||||
@api.depends('procurement_ids.purchase_line_id')
|
||||
def _get_purchase_order_lines(self):
|
||||
purchase_list = []
|
||||
for procurement_id in self.procurement_ids:
|
||||
if procurement_id.purchase_line_id and \
|
||||
procurement_id.purchase_line_id.id:
|
||||
purchase_list.append(procurement_id.purchase_line_id.id)
|
||||
self.purchase_order_line_ids = [(6, 0, purchase_list)]
|
||||
|
||||
@api.one
|
||||
@api.depends('procurement_ids.purchase_line_id')
|
||||
def _compute_qty_purchased(self):
|
||||
self.qty_purchased = self._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',
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
@api.multi
|
||||
def action_view_purchase_order(self):
|
||||
action = self.env.ref('purchase.purchase_rfq')
|
||||
result = action.read()[0]
|
||||
order_ids = []
|
||||
for procurement_id in self.procurement_ids:
|
||||
order_ids.append(procurement_id.purchase_id.id)
|
||||
result['domain'] = [('id', 'in', order_ids)]
|
||||
return result
|
||||
|
||||
@api.multi
|
||||
def _get_rma_purchased_qty(self):
|
||||
self.ensure_one()
|
||||
qty = 0.0
|
||||
for procurement_id in self.procurement_ids:
|
||||
purchase_line = procurement_id.purchase_line_id
|
||||
if self.type == 'supplier':
|
||||
qty += purchase_line.product_qty
|
||||
else:
|
||||
qty = 0.0
|
||||
return qty
|
||||
33
rma_purchase/views/rma_order_line_view.xml
Normal file
33
rma_purchase/views/rma_order_line_view.xml
Normal file
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<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="quantities" position="inside">
|
||||
<group>
|
||||
<field name="qty_purchased"/>
|
||||
</group>
|
||||
</group>
|
||||
<notebook position="inside">
|
||||
<page name="purchase" string="Purchase Lines">
|
||||
<field name="purchase_order_line_ids" nolabel="1"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
33
rma_purchase/views/rma_order_view.xml
Normal file
33
rma_purchase/views/rma_order_view.xml
Normal file
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<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>
|
||||
</div>
|
||||
<div name='button_box' position="inside">
|
||||
<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>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
6
rma_purchase/wizards/__init__.py
Normal file
6
rma_purchase/wizards/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
# -*- 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 . import rma_make_picking
|
||||
from . import rma_add_purchase
|
||||
114
rma_purchase/wizards/rma_add_purchase.py
Normal file
114
rma_purchase/wizards/rma_add_purchase.py
Normal file
@@ -0,0 +1,114 @@
|
||||
# -*- 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)
|
||||
|
||||
import time
|
||||
from openerp import models, fields, exceptions, api, _
|
||||
from openerp.exceptions import ValidationError
|
||||
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT as DT_FORMAT
|
||||
import openerp.addons.decimal_precision as dp
|
||||
|
||||
|
||||
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('rma.order',
|
||||
string='RMA Order',
|
||||
readonly=True,
|
||||
ondelete='cascade')
|
||||
|
||||
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')
|
||||
|
||||
def _prepare_rma_line_from_po_line(self, line):
|
||||
operation = line.product_id.rma_operation_id and \
|
||||
line.product_id.rma_operation_id.id or False
|
||||
if not operation:
|
||||
operation = line.product_id.categ_id.rma_operation_id and \
|
||||
line.product_id.categ_id.rma_operation_id.id or False
|
||||
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)
|
||||
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 an rma route")
|
||||
data.update(
|
||||
{'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,
|
||||
'refund_policy': operation.refund_policy,
|
||||
'delivery_policy': operation.delivery_policy
|
||||
})
|
||||
return data
|
||||
|
||||
@api.model
|
||||
def _get_rma_data(self):
|
||||
data = {
|
||||
'date_rma': fields.Datetime.now(),
|
||||
'delivery_address_id': self.purchase_id.partner_id.id,
|
||||
'invoice_address_id': self.purchase_id.partner_id.id
|
||||
}
|
||||
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'}
|
||||
77
rma_purchase/wizards/rma_add_purchase.xml
Normal file
77
rma_purchase/wizards/rma_add_purchase.xml
Normal file
@@ -0,0 +1,77 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<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="product.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">
|
||||
<button name="action_rma_done" position="after">
|
||||
<button name="%(action_rma_add_purchase)d"
|
||||
string="Add From Purchase Order"
|
||||
type="action"
|
||||
states="draft,to_approve"/>
|
||||
</button>
|
||||
</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 @@
|
||||
# -*- 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 openerp import models, fields, exceptions, api, _
|
||||
|
||||
|
||||
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')
|
||||
Reference in New Issue
Block a user