[MIGR] mrp_repair

This commit is contained in:
Mitali Patel
2016-07-04 16:22:36 +02:00
committed by Thibault Delavallée
parent c3f23afb61
commit 653d63153e
4 changed files with 501 additions and 637 deletions
File diff suppressed because it is too large Load Diff
+10 -10
View File
@@ -44,18 +44,18 @@
</h1>
<group>
<group>
<field name="product_id" on_change="onchange_product_id(product_id)" domain="[('type', 'in', ['product', 'consu'])]"/>
<field name="product_id" domain="[('type', 'in', ['product', 'consu'])]"/>
<label for="product_qty"/>
<div>
<field name="product_qty" class="oe_inline"/>
<field name="product_uom" groups="product.group_uom" on_change="onchange_product_uom(product_id, product_uom)" class="oe_inline"/>
<field name="product_uom" groups="product.group_uom" class="oe_inline"/>
</div>
<field name="lot_id" domain="[('product_id', '=', product_id)]" context="{'default_product_id': product_id}" groups="stock.group_production_lot"/>
<field name="partner_id" on_change="onchange_partner_id(partner_id,address_id)" attrs="{'required':[('invoice_method','!=','none')]}"/>
<field name="partner_id" attrs="{'required':[('invoice_method','!=','none')]}"/>
<field name="address_id" groups="sale.group_delivery_invoice_address"/>
</group>
<group>
<field name="location_id" on_change="onchange_location_id(location_id)" groups="stock.group_stock_multi_locations" domain="[('usage', 'in', ('internal', 'customer'))]"/>
<field name="location_id" groups="stock.group_stock_multi_locations" domain="[('usage', 'in', ('internal', 'customer'))]"/>
<field name="location_dest_id" groups="stock.group_stock_multi_locations" domain="[('usage', 'in', ('internal', 'customer'))]"/>
<field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/>
<field name="guarantee_limit"/>
@@ -69,7 +69,7 @@
<page string="Repair Line">
<group col="4">
<field name="name"/>
<field name="product_id" on_change="product_id_change(parent.pricelist_id, product_id, product_uom, product_uom_qty, parent.partner_id, False, context)"/>
<field name="product_id"/>
<label for="product_uom_qty"/>
<div>
<field name="product_uom_qty" class="oe_inline"/>
@@ -77,7 +77,7 @@
</div>
<field name="price_unit"/>
<field name="price_subtotal" widget="monetary"/>
<field name="type" on_change="onchange_operation_type(type,parent.guarantee_limit,parent.company_id,context)"/>
<field name="type"/>
<field name="to_invoice"/>
<field name="tax_id" widget="many2many_tags" domain="[('type_tax_use','=','sale')]"/>
<field name="invoiced"/>
@@ -94,8 +94,8 @@
</notebook>
</form>
<tree string="Operations" editable="bottom">
<field name="type" on_change="onchange_operation_type(type,parent.guarantee_limit,parent.company_id,context)"/>
<field name="product_id" on_change="product_id_change(parent.pricelist_id, product_id, product_uom, product_uom_qty, parent.partner_id, False, context)"/>
<field name="type"/>
<field name="product_id"/>
<field name='name'/>
<field name="lot_id" domain="[('product_id', '=', product_id)]" context="{'default_product_id': product_id}" groups="stock.group_production_lot"/>
<field name="location_id" groups="stock.group_stock_multi_locations"/>
@@ -140,7 +140,7 @@
<group string="Product Information">
<group>
<field name="to_invoice"/>
<field name="product_id" on_change="product_id_change(parent.pricelist_id, product_id, product_uom, product_uom_qty, parent.partner_id, parent.guarantee_limit, context)"/>
<field name="product_id"/>
<label for="product_uom_qty"/>
<div>
<field name="product_uom_qty" string="Quantity" class="oe_inline"/>
@@ -163,7 +163,7 @@
</group>
</form>
<tree string="Fees" editable="bottom">
<field name="product_id" on_change="product_id_change(parent.pricelist_id, product_id, product_uom, product_uom_qty, parent.partner_id,parent.guarantee_limit, context)"/>
<field name="product_id"/>
<field name='name'/>
<field name="product_uom_qty" string="Quantity"/>
<field name="product_uom" string="Unit of Measure" groups="product.group_uom"/>
+18 -41
View File
@@ -1,57 +1,34 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from openerp.osv import osv,fields
from openerp.tools.translate import _
from openerp.exceptions import UserError
from odoo import api, models, _
from odoo.exceptions import UserError
class repair_cancel(osv.osv_memory):
class RepairCancel(models.TransientModel):
_name = 'mrp.repair.cancel'
_description = 'Cancel Repair'
def cancel_repair(self, cr, uid, ids, context=None):
""" Cancels the repair
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param ids: List of IDs selected
@param context: A standard dictionary
@return:
"""
if context is None:
context = {}
record_id = context and context.get('active_id', False) or False
assert record_id, _('Active ID not Found')
repair_order_obj = self.pool.get('mrp.repair')
repair_line_obj = self.pool.get('mrp.repair.line')
repair_order = repair_order_obj.browse(cr, uid, record_id, context=context)
if repair_order.invoiced or repair_order.invoice_method == 'none':
repair_order_obj.action_cancel(cr, uid, [record_id], context=context)
@api.multi
def cancel_repair(self):
if not self._context.get('active_id'):
return {'type': 'ir.actions.act_window_close'}
repair = self.env['mrp.repair'].browse(self._context['active_id'])
if repair.invoiced or repair.invoice_method == 'none':
repair.action_cancel()
else:
raise UserError(_('Repair order is not invoiced.'))
return {'type': 'ir.actions.act_window_close'}
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
""" Changes the view dynamically
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param context: A standard dictionary
@return: New arch of view.
"""
if context is None:
context = {}
res = super(repair_cancel, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar,submenu=False)
record_id = context and context.get('active_id', False) or False
active_model = context.get('active_model')
if not record_id or (active_model and active_model != 'mrp.repair'):
@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
res = super(RepairCancel, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar,submenu=submenu)
repair_id = self._context.get('active_id')
if not repair_id or self._context.get('active_model') != 'mrp.repair':
return res
repair_order = self.pool.get('mrp.repair').browse(cr, uid, record_id, context=context)
if not repair_order.invoiced:
repair = self.env['mrp.repair'].browse(repair_id)
if not repair.invoiced:
res['arch'] = """
<form string="Cancel Repair" version="7.0">
<header>
@@ -1,51 +1,36 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from openerp.osv import fields, osv
from odoo import api, fields, models
class make_invoice(osv.osv_memory):
class MakeInvoice(models.TransientModel):
_name = 'mrp.repair.make_invoice'
_description = 'Make Invoice'
_columns = {
'group': fields.boolean('Group by partner invoice address'),
}
group = fields.Boolean('Group by partner invoice address')
def make_invoices(self, cr, uid, ids, context=None):
""" Generates invoice(s) of selected records.
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param ids: List of IDs selected
@param context: A standard dictionary
@return: Loads the view of new invoice(s).
"""
if context is None:
context = {}
inv = self.browse(cr, uid, ids[0], context=context)
order_obj = self.pool.get('mrp.repair')
mod_obj = self.pool.get('ir.model.data')
newinv = order_obj.action_invoice_create(cr, uid, context['active_ids'],
group=inv.group,context=context)
# We have to trigger the workflow of the given repairs, otherwise they remain 'to be invoiced'.
# Note that the signal 'action_invoice_create' will trigger another call to the method 'action_invoice_create',
# but that second call will not do anything, since the repairs are already invoiced.
order_obj.signal_workflow(cr, uid, context['active_ids'], 'action_invoice_create')
form_res = mod_obj.get_object_reference(cr, uid, 'account', 'invoice_form')
form_id = form_res and form_res[1] or False
tree_res = mod_obj.get_object_reference(cr, uid, 'account', 'invoice_tree')
tree_id = tree_res and tree_res[1] or False
@api.multi
def make_invoices(self):
if not self._context.get('active_ids'):
return {'type': 'ir.actions.act_window_close'}
new_invoice = {}
for wizard in self:
repairs = self.env['mrp.repair'].browse(self._context['active_ids'])
new_invoice = repairs.action_invoice_create(group=wizard.group)
# We have to trigger the workflow of the given repairs, otherwise they remain 'to be invoiced'.
# Note that the signal 'action_invoice_create' will trigger another call to the method 'action_invoice_create',
# but that second call will not do anything, since the repairs are already invoiced.
repairs.signal_workflow('action_invoice_create')
return {
'domain': [('id','in', newinv.values())],
'domain': [('id', 'in', new_invoice.values())],
'name': 'Invoices',
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'account.invoice',
'view_id': False,
'views': [(tree_id, 'tree'),(form_id, 'form')],
'views': [(self.env.ref('account.invoice_tree').id, 'tree'), (self.env.ref('account.invoice_form').id, 'form')],
'context': "{'type':'out_invoice'}",
'type': 'ir.actions.act_window'
}