mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[10.0][IMP]add report for rma group
This commit is contained in:
@@ -117,6 +117,7 @@ Contributors
|
||||
* Bhavesh Odedra <bodedra@opensourceintegrators.com>
|
||||
* Akim Juillerat <akim.juillerat@camptocamp.com>
|
||||
* Alexandre Fayolle <alexandre.fayolle@camptocamp.com>
|
||||
* Chafique Delli <chafique.delli@akretion.com>
|
||||
|
||||
Maintainer
|
||||
----------
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
# Copyright (C) 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 import api, fields, models, _
|
||||
from odoo.exceptions import UserError
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
@@ -52,10 +53,38 @@ class RmaOrder(models.Model):
|
||||
for rec in self:
|
||||
rec.line_count = len(rec._get_valid_lines())
|
||||
|
||||
@api.depends('rma_line_ids', 'rma_line_ids.state')
|
||||
@api.multi
|
||||
def _compute_state(self):
|
||||
for rec in self:
|
||||
rma_line_done = self.env['rma.order.line'].search_count(
|
||||
[('id', 'in', rec.rma_line_ids.ids), ('state', '=', 'done')])
|
||||
rma_line_approved = self.env['rma.order.line'].search_count(
|
||||
[('id', 'in', rec.rma_line_ids.ids),
|
||||
('state', '=', 'approved')])
|
||||
rma_line_to_approve = self.env['rma.order.line'].search_count(
|
||||
[('id', 'in', rec.rma_line_ids.ids),
|
||||
('state', '=', 'to_approve')])
|
||||
if rma_line_done != 0:
|
||||
state = 'done'
|
||||
elif rma_line_approved != 0:
|
||||
state = 'approved'
|
||||
elif rma_line_to_approve != 0:
|
||||
state = 'to_approve'
|
||||
else:
|
||||
state = 'draft'
|
||||
rec.state = state
|
||||
|
||||
@api.model
|
||||
def _default_date_rma(self):
|
||||
return datetime.now()
|
||||
|
||||
@api.model
|
||||
def _default_warehouse_id(self):
|
||||
warehouse = self.env['stock.warehouse'].search(
|
||||
[('company_id', '=', self.env.user.company_id.id)], limit=1)
|
||||
return warehouse
|
||||
|
||||
name = fields.Char(
|
||||
string='Group Number', index=True, copy=False)
|
||||
type = fields.Selection(
|
||||
@@ -86,6 +115,54 @@ class RmaOrder(models.Model):
|
||||
company_id = fields.Many2one('res.company', string='Company',
|
||||
required=True, default=lambda self:
|
||||
self.env.user.company_id)
|
||||
assigned_to = fields.Many2one(
|
||||
comodel_name='res.users', track_visibility='onchange',
|
||||
default=lambda self: self.env.uid,
|
||||
)
|
||||
requested_by = fields.Many2one(
|
||||
comodel_name='res.users', track_visibility='onchange',
|
||||
default=lambda self: self.env.uid,
|
||||
)
|
||||
in_warehouse_id = fields.Many2one(
|
||||
comodel_name='stock.warehouse',
|
||||
string='Inbound Warehouse',
|
||||
required=True,
|
||||
default=_default_warehouse_id,
|
||||
)
|
||||
customer_to_supplier = fields.Boolean(
|
||||
'The customer will send to the supplier',
|
||||
)
|
||||
supplier_to_customer = fields.Boolean(
|
||||
'The supplier will send to the customer',
|
||||
)
|
||||
supplier_address_id = fields.Many2one(
|
||||
comodel_name='res.partner',
|
||||
string='Supplier Address',
|
||||
help="Address of the supplier in case of Customer RMA operation "
|
||||
"dropship.")
|
||||
customer_address_id = fields.Many2one(
|
||||
comodel_name='res.partner',
|
||||
string='Customer Address',
|
||||
help="Address of the customer in case of Supplier RMA operation "
|
||||
"dropship.")
|
||||
state = fields.Selection(
|
||||
compute=_compute_state,
|
||||
selection=[('draft', 'Draft'),
|
||||
('to_approve', 'To Approve'),
|
||||
('approved', 'Approved'),
|
||||
('done', 'Done')],
|
||||
string='State', default='draft', store=True
|
||||
)
|
||||
|
||||
@api.constrains("partner_id", "rma_line_ids")
|
||||
def _check_partner_id(self):
|
||||
if self.rma_line_ids and self.partner_id != self.mapped(
|
||||
"rma_line_ids.partner_id"):
|
||||
raise UserError(_(
|
||||
"Group partner and RMA's partner must be the same."))
|
||||
if len(self.mapped("rma_line_ids.partner_id")) > 1:
|
||||
raise UserError(_(
|
||||
"All grouped RMA's should have same partner."))
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
@@ -183,3 +260,24 @@ class RmaOrder(models.Model):
|
||||
result['views'] = [(res and res.id or False, 'form')]
|
||||
result['res_id'] = related_lines[0]
|
||||
return result
|
||||
|
||||
@api.onchange('in_warehouse_id')
|
||||
def _onchange_in_warehouse_id(self):
|
||||
if self.in_warehouse_id and self.rma_line_ids:
|
||||
self.rma_line_ids.write(
|
||||
{'in_warehouse_id': self.in_warehouse_id.id,
|
||||
'location_id': self.in_warehouse_id.lot_rma_id.id})
|
||||
|
||||
@api.onchange('customer_to_supplier', 'supplier_address_id')
|
||||
def _onchange_customer_to_supplier(self):
|
||||
if self.type == 'customer' and self.rma_line_ids:
|
||||
self.rma_line_ids.write(
|
||||
{'customer_to_supplier': self.customer_to_supplier,
|
||||
'supplier_address_id': self.supplier_address_id.id})
|
||||
|
||||
@api.onchange('supplier_to_customer', 'customer_address_id')
|
||||
def _onchange_supplier_to_customer(self):
|
||||
if self.type == 'supplier' and self.rma_line_ids:
|
||||
self.rma_line_ids.write(
|
||||
{'supplier_to_customer': self.supplier_to_customer,
|
||||
'customer_address_id': self.customer_address_id.id})
|
||||
|
||||
@@ -9,5 +9,13 @@
|
||||
file="rma.report_rma_order_line"
|
||||
name="rma.report_rma_order_line"
|
||||
/>
|
||||
<report
|
||||
id="rma_order_report"
|
||||
string="RMA Group"
|
||||
model="rma.order"
|
||||
report_type="qweb-pdf"
|
||||
file="rma.report_rma_order"
|
||||
name="rma.report_rma_order"
|
||||
/>
|
||||
</data>
|
||||
</odoo>
|
||||
|
||||
@@ -100,4 +100,101 @@
|
||||
</t>
|
||||
</t>
|
||||
</template>
|
||||
|
||||
|
||||
<template id="report_rma_order_document">
|
||||
<t t-call="report.external_layout">
|
||||
<t t-set="doc" t-value="doc.with_context({'lang':doc.partner_id.lang})" />
|
||||
<div class="page">
|
||||
<div class="oe_structure"/>
|
||||
<div class="row">
|
||||
<div class="col-xs-6">
|
||||
<t t-if="(doc.customer_to_supplier==False and doc.type=='customer') or (doc.supplier_to_customer==False and doc.type=='supplier')">
|
||||
<strong>Shipping address:</strong>
|
||||
<div class="mt8">
|
||||
<div t-field="doc.in_warehouse_id.partner_id"
|
||||
t-options='{"widget": "contact", "fields": ["address", "name", "phone", "fax"], "no_marker": True, "phone_icons": True}'/>
|
||||
<p t-if="doc.in_warehouse_id.partner_id.vat">VAT: <span t-field="doc.in_warehouse_id.partner_id.vat"/></p>
|
||||
</div>
|
||||
</t>
|
||||
<div t-if="doc.customer_to_supplier and doc.type=='customer'" class="mt8">
|
||||
<strong>Shipping address:</strong>
|
||||
<div t-field="doc.supplier_address_id"
|
||||
t-options='{"widget": "contact", "fields": ["address", "name", "phone", "fax"], "no_marker": True, "phone_icons": True}'/>
|
||||
<p t-if="doc.supplier_address_id.vat">VAT: <span t-field="doc.supplier_address_id.vat"/></p>
|
||||
</div>
|
||||
<div t-if="doc.supplier_to_customer and doc.type=='supplier'" class="mt8">
|
||||
<strong>Shipping address:</strong>
|
||||
<div t-field="doc.customer_address_id"
|
||||
t-options='{"widget": "contact", "fields": ["address", "name", "phone", "fax"], "no_marker": True, "phone_icons": True}'/>
|
||||
<p t-if="doc.customer_address_id.vat">VAT: <span t-field="doc.customer_address_id.vat"/></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-3 col-xs-offset-1">
|
||||
<strong t-if="doc.type=='customer'">Customer:</strong>
|
||||
<strong t-if="doc.type=='supplier'">Supplier:</strong>
|
||||
<div t-field="doc.partner_id"
|
||||
t-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": True}' />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h2>
|
||||
<span t-field="doc.name"/>
|
||||
</h2>
|
||||
|
||||
<div class="row mt32 mb32" id="informations">
|
||||
<div t-if="doc.reference" class="col-xs-3">
|
||||
<strong>Reference:</strong>
|
||||
<p t-field="doc.reference"/>
|
||||
</div>
|
||||
<div t-if="doc.date_rma" class="col-xs-3">
|
||||
<strong>Date Ordered:</strong>
|
||||
<p t-field="doc.date_rma"/>
|
||||
</div>
|
||||
<div t-if="doc.requested_by.name" class="col-xs-3">
|
||||
<strong>Contact Person:</strong>
|
||||
<p t-field="doc.requested_by.name"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<table class="table table-condensed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Origin</th>
|
||||
<th>Operation</th>
|
||||
<th>Product</th>
|
||||
<th class="text-right">Quantity</th>
|
||||
<th class="text-right">Unit Price</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr t-foreach="doc.rma_line_ids" t-as="l">
|
||||
<td><span t-field="l.origin"/></td>
|
||||
<td><span t-field="l.operation_id.name"/></td>
|
||||
<td><span t-field="l.product_id"/></td>
|
||||
<td class="text-right">
|
||||
<span t-field="l.product_qty"/>
|
||||
<span t-field="l.uom_id" groups="product.group_uom"/>
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<span t-field="l.price_unit"/>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div t-if="doc.comment">
|
||||
<strong><p>Additional Information</p></strong>
|
||||
<span t-field="doc.comment"></span>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</template>
|
||||
|
||||
<template id="report_rma_order">
|
||||
<t t-call="report.html_container">
|
||||
<t t-foreach="docs" t-as="doc">
|
||||
<t t-call="rma.report_rma_order_document" t-lang="doc.partner_id.lang"/>
|
||||
</t>
|
||||
</t>
|
||||
</template>
|
||||
</odoo>
|
||||
|
||||
@@ -78,9 +78,26 @@
|
||||
/>
|
||||
</group>
|
||||
<group name="info">
|
||||
<field name="reference"/>
|
||||
<field name="date_rma"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="reference"/>
|
||||
<field name="date_rma" attrs="{'readonly':[('state', '!=', 'draft')]}"/>
|
||||
</group>
|
||||
<group name="contact" string="Contact">
|
||||
<field name="requested_by" readonly="1"/>
|
||||
<field name="assigned_to" attrs="{'readonly':[('state', '!=', 'draft')]}"/>
|
||||
</group>
|
||||
</group>
|
||||
<group name="inbound_route" string="Inbound">
|
||||
<field name="in_warehouse_id" attrs="{'readonly':[('state', '!=', 'draft')]}"/>
|
||||
<field name="customer_to_supplier" attrs="{'readonly':[('state', '!=', 'draft')]}"/>
|
||||
<field name="state" invisible="True"/>
|
||||
<field name="supplier_address_id"
|
||||
context="{'show_address': 1}"
|
||||
options="{'always_reload': 1}"
|
||||
attrs="{'required':[('customer_to_supplier', '=', True)],
|
||||
'invisible':[('customer_to_supplier', '=', False)],
|
||||
'readonly':[('state', '!=', 'draft')]}"/>
|
||||
</group>
|
||||
<notebook colspan="4">
|
||||
<page string="RMA Lines" name="lines">
|
||||
<field name="rma_line_ids" context="{'default_rma_id': active_id,
|
||||
@@ -155,14 +172,34 @@
|
||||
</h1>
|
||||
</div>
|
||||
<group name="partner">
|
||||
<field name="state" invisible="1"/>
|
||||
<field name="partner_id"
|
||||
domain="[('supplier','=',True)]"
|
||||
string="Supplier"/>
|
||||
string="Supplier"
|
||||
attrs="{'readonly':[('state', '!=', 'draft')]}"/>
|
||||
</group>
|
||||
<group>
|
||||
<group col="4">
|
||||
<field name="reference"/>
|
||||
<field name="date_rma"/>
|
||||
<field name="date_rma" attrs="{'readonly':[('state', '!=', 'draft')]}"/>
|
||||
</group>
|
||||
<group name="contact" string="Contact">
|
||||
<field name="requested_by" readonly="1"/>
|
||||
<field name="assigned_to" attrs="{'readonly':[('state', '!=', 'draft')]}"/>
|
||||
</group>
|
||||
</group>
|
||||
<group name="route">
|
||||
<group name="inbound_route" string="Inbound">
|
||||
<field name="in_warehouse_id" attrs="{'readonly':[('state', '!=', 'draft')]}"/>
|
||||
</group>
|
||||
<group name="outbound_route" string="Outbound">
|
||||
<field name="supplier_to_customer" attrs="{'readonly':[('state', '!=', 'draft')]}"/>
|
||||
<field name="customer_address_id"
|
||||
context="{'show_address': 1}"
|
||||
options="{'always_reload': 1}"
|
||||
attrs="{'required':[('supplier_to_customer', '=', True)],
|
||||
'invisible':[('supplier_to_customer', '=', False)],
|
||||
'readonly':[('state', '!=', 'draft')]}"/>
|
||||
</group>
|
||||
</group>
|
||||
<notebook colspan="4">
|
||||
@@ -292,4 +329,5 @@
|
||||
groups="rma.group_rma_manager"
|
||||
sequence="30"
|
||||
parent="stock.menu_stock_config_settings"/>
|
||||
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user