mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
Merge pull request #100 from ForgeFlow/12.0-enh-rma_sale
[12.0][ENH] rma_sale
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
<button type="object"
|
||||
name="action_open_partner_rma"
|
||||
class="oe_stat_button"
|
||||
icon="fa-eject"
|
||||
icon="fa-dropbox"
|
||||
attrs="{'invisible':[('customer', '=', False)]}"
|
||||
groups="rma.group_rma_customer_user,rma.group_rma_supplier_user">
|
||||
<field name="rma_line_count" widget="statinfo"
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<div class="oe_button_box" attrs="{'invisible': [('rma_count', '=', 0)]}">
|
||||
<button type="object" name="action_view_rma_customer"
|
||||
class="oe_stat_button"
|
||||
icon="fa-eject"
|
||||
icon="fa-dropbox"
|
||||
groups="rma.group_rma_customer_user,rma.group_rma_supplier_user">
|
||||
<field name="rma_count" widget="statinfo"
|
||||
string="RMA"/>
|
||||
@@ -28,7 +28,7 @@
|
||||
<div class="oe_button_box" attrs="{'invisible': [('rma_count', '=', 0)]}">
|
||||
<button type="object" name="action_view_rma_supplier"
|
||||
class="oe_stat_button"
|
||||
icon="fa-eject"
|
||||
icon="fa-dropbox"
|
||||
groups="rma.group_rma_customer_user,rma.group_rma_supplier_user">
|
||||
<field name="rma_count" widget="statinfo"
|
||||
string="RMA"/>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
{
|
||||
'name': 'RMA Sale',
|
||||
'version': '12.0.1.0.0',
|
||||
'version': '12.0.1.1.0',
|
||||
'license': 'LGPL-3',
|
||||
'category': 'RMA',
|
||||
'summary': 'Links RMA with Sales Orders',
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
from . import sale_order_line
|
||||
from . import sale_order
|
||||
from . import rma_order_line
|
||||
from . import rma_order
|
||||
from . import rma_operation
|
||||
|
||||
38
rma_sale/models/sale_order.py
Normal file
38
rma_sale/models/sale_order.py
Normal file
@@ -0,0 +1,38 @@
|
||||
# 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 SaleOrder(models.Model):
|
||||
_inherit = "sale.order"
|
||||
|
||||
rma_line_ids = fields.One2many(
|
||||
comodel_name='rma.order.line',
|
||||
compute='compute_rma_line')
|
||||
|
||||
rma_count = fields.Integer(
|
||||
compute='compute_rma_count', string='# of RMA')
|
||||
|
||||
def compute_rma_count(self):
|
||||
for so in self:
|
||||
rmas = self.mapped('rma_line_ids')
|
||||
so.rma_count = len(rmas)
|
||||
|
||||
def compute_rma_line(self):
|
||||
for so in self:
|
||||
so.rma_line_ids = so.mapped('order_line.rma_line_id')
|
||||
|
||||
@api.multi
|
||||
def action_view_rma(self):
|
||||
action = self.env.ref('rma.action_rma_customer_lines')
|
||||
result = action.read()[0]
|
||||
rma_ids = self.mapped('rma_line_ids').ids
|
||||
if rma_ids:
|
||||
# choose the view_mode accordingly
|
||||
if len(rma_ids) > 1:
|
||||
result['domain'] = [('id', 'in', rma_ids)]
|
||||
else:
|
||||
res = self.env.ref('rma.view_rma_line_form', False)
|
||||
result['views'] = [(res and res.id or False, 'form')]
|
||||
result['res_id'] = rma_ids[0]
|
||||
return result
|
||||
@@ -14,4 +14,27 @@
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
|
||||
<record id="view_order_form_inherit_sale_rma" model="ir.ui.view">
|
||||
<field name="name">sale.order.form.sale.rma</field>
|
||||
<field name="model">sale.order</field>
|
||||
<field name="inherit_id" ref="sale.view_order_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<data>
|
||||
<xpath expr="//button[@name='action_view_invoice']" position="before">
|
||||
<button type="object"
|
||||
name="action_view_rma"
|
||||
class="oe_stat_button"
|
||||
icon="fa-dropbox"
|
||||
attrs="{'invisible': [('rma_count', '=', 0)]}"
|
||||
groups="rma.group_rma_customer_user">
|
||||
<field name="rma_count" widget="statinfo" string="RMA"/>
|
||||
</button>
|
||||
</xpath>
|
||||
</data>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
||||
@@ -14,7 +14,7 @@ class RmaLineMakeSaleOrder(models.TransientModel):
|
||||
domain=[('customer', '=', True)])
|
||||
item_ids = fields.One2many(
|
||||
comodel_name='rma.order.line.make.sale.order.item',
|
||||
inverse_name='wiz_id', string='Items')
|
||||
inverse_name='wiz_id', string='Items', readonly=False)
|
||||
sale_order_id = fields.Many2one(
|
||||
comodel_name='sale.order', string='Sales Order', required=False,
|
||||
domain=[('state', '=', 'draft')])
|
||||
@@ -58,16 +58,16 @@ class RmaLineMakeSaleOrder(models.TransientModel):
|
||||
return res
|
||||
|
||||
@api.model
|
||||
def _prepare_sale_order(self, out_warehouse, company, item):
|
||||
def _prepare_sale_order(self, line):
|
||||
if not self.partner_id:
|
||||
raise exceptions.Warning(
|
||||
_('Enter a customer.'))
|
||||
customer = self.partner_id
|
||||
data = {
|
||||
'origin': item.line_id.name,
|
||||
'origin': line.name,
|
||||
'partner_id': customer.id,
|
||||
'warehouse_id': out_warehouse.id,
|
||||
'company_id': company.id,
|
||||
'warehouse_id': line.out_warehouse_id.id,
|
||||
'company_id': line.company_id.id,
|
||||
}
|
||||
return data
|
||||
|
||||
@@ -102,11 +102,9 @@ class RmaLineMakeSaleOrder(models.TransientModel):
|
||||
if self.sale_order_id:
|
||||
sale = self.sale_order_id
|
||||
if not sale:
|
||||
po_data = self._prepare_sale_order(
|
||||
line.out_warehouse_id,
|
||||
line.company_id,
|
||||
item)
|
||||
po_data = self._prepare_sale_order(line)
|
||||
sale = sale_obj.create(po_data)
|
||||
sale.name = sale.name + ' - ' + line.name
|
||||
|
||||
so_line_data = self._prepare_sale_order_line(sale, item)
|
||||
so_line_obj.create(so_line_data)
|
||||
@@ -125,7 +123,8 @@ class RmaLineMakeSaleOrderItem(models.TransientModel):
|
||||
wiz_id = fields.Many2one(
|
||||
comodel_name='rma.order.line.make.sale.order', string='Wizard')
|
||||
line_id = fields.Many2one(
|
||||
comodel_name='rma.order.line', string='RMA Line')
|
||||
comodel_name='rma.order.line', string='RMA Line',
|
||||
compute='compute_line_id')
|
||||
rma_id = fields.Many2one(
|
||||
comodel_name='rma.order', related='line_id.rma_id', readonly=False)
|
||||
product_id = fields.Many2one(
|
||||
@@ -138,3 +137,17 @@ class RmaLineMakeSaleOrderItem(models.TransientModel):
|
||||
out_warehouse_id = fields.Many2one(
|
||||
comodel_name='stock.warehouse', string='Outbound Warehouse')
|
||||
free_of_charge = fields.Boolean(string='Free of Charge')
|
||||
|
||||
def compute_line_id(self):
|
||||
rma_line_obj = self.env['rma.order.line']
|
||||
for rec in self:
|
||||
if not self.env.context['active_ids']:
|
||||
return
|
||||
rma_line_ids = self.env.context['active_ids'] or []
|
||||
lines = rma_line_obj.browse(rma_line_ids)
|
||||
rec.line_id = lines[0]
|
||||
|
||||
@api.onchange('product_id')
|
||||
def onchange_product_id(self):
|
||||
if self.product_id:
|
||||
self.name = self.product_id.name
|
||||
|
||||
@@ -26,9 +26,10 @@
|
||||
<newline/>
|
||||
<group>
|
||||
<field name="item_ids" nolabel="1" colspan="2">
|
||||
<tree string="Details" editable="bottom" create="false">
|
||||
<tree string="Details" editable="bottom">
|
||||
<field name="wiz_id" invisible="True"/>
|
||||
<field name="line_id"
|
||||
options="{'no_open': true}"/>
|
||||
invisible="True"/>
|
||||
<field name="product_id"/>
|
||||
<field name="name"/>
|
||||
<field name="product_qty"/>
|
||||
|
||||
Reference in New Issue
Block a user