|
|
@ -20,20 +20,23 @@ |
|
|
|
# |
|
|
|
############################################################################# |
|
|
|
############################################################################# |
|
|
|
from datetime import datetime, date, timedelta |
|
|
|
from datetime import datetime |
|
|
|
from odoo import models, fields, api, _ |
|
|
|
from odoo.exceptions import Warning, UserError |
|
|
|
from odoo.exceptions import UserError |
|
|
|
import pytz |
|
|
|
|
|
|
|
|
|
|
|
class MobileServiceShop(models.Model): |
|
|
|
_name = 'mobile.service' |
|
|
|
_rec_name = 'name' |
|
|
|
_description = "Mobile Service" |
|
|
|
_inherit = ['mail.thread', 'mail.activity.mixin'] |
|
|
|
|
|
|
|
name = fields.Char(string='Service Number', copy=False, default="New") |
|
|
|
person_name = fields.Many2one('res.partner', string="Customer Name", required=True) |
|
|
|
contact_no = fields.Char(related='person_name.mobile', string="Contact Number") |
|
|
|
person_name = fields.Many2one('res.partner', string="Customer Name", |
|
|
|
required=True) |
|
|
|
contact_no = fields.Char(related='person_name.mobile', |
|
|
|
string="Contact Number") |
|
|
|
email_id = fields.Char(related='person_name.email', string="Email") |
|
|
|
|
|
|
|
street = fields.Char(related='person_name.street', string="Address") |
|
|
@ -41,14 +44,16 @@ class MobileServiceShop(models.Model): |
|
|
|
city = fields.Char(related='person_name.city', string="Address") |
|
|
|
state_id = fields.Many2one(related='person_name.state_id', string="Address") |
|
|
|
zip = fields.Char(related='person_name.zip', string="Address") |
|
|
|
country_id = fields.Many2one(related='person_name.country_id', string="Address") |
|
|
|
country_id = fields.Many2one(related='person_name.country_id', |
|
|
|
string="Address") |
|
|
|
|
|
|
|
brand_name = fields.Many2one('mobile.brand', string="Mobile Brand") |
|
|
|
is_in_warranty = fields.Boolean( |
|
|
|
'In Warranty', default=False, |
|
|
|
help="Specify if the product is in warranty.") |
|
|
|
|
|
|
|
warranty_number = fields.Char(string="Warranty No ", help="warranty details") |
|
|
|
warranty_number = fields.Char(string="Warranty No ", |
|
|
|
help="warranty details") |
|
|
|
|
|
|
|
re_repair = fields.Boolean( |
|
|
|
'Re-repair', default=False, |
|
|
@ -56,48 +61,69 @@ class MobileServiceShop(models.Model): |
|
|
|
|
|
|
|
imei_no = fields.Char(string="IMEI Number") |
|
|
|
|
|
|
|
model_name = fields.Many2one('brand.model', string="Model", domain="[('mobile_brand_name','=',brand_name)]") |
|
|
|
image_medium = fields.Binary(related='model_name.image_medium', store=True, attachment=True) |
|
|
|
date_request = fields.Date(string="Requested date", default=fields.Date.context_today) |
|
|
|
model_name = fields.Many2one('brand.model', string="Model", |
|
|
|
domain="[('mobile_brand_name','=',brand_name)]") |
|
|
|
image_medium = fields.Binary(related='model_name.image_medium', store=True, |
|
|
|
attachment=True) |
|
|
|
date_request = fields.Date(string="Requested date", |
|
|
|
default=fields.Date.context_today) |
|
|
|
return_date = fields.Date(string="Return date", required=True) |
|
|
|
technician_name = fields.Many2one('res.users', string="Technician Name", |
|
|
|
default=lambda self: self.env.user, required=True) |
|
|
|
service_state = fields.Selection([('draft', 'Draft'), ('assigned', 'Assigned'), |
|
|
|
default=lambda self: self.env.user, |
|
|
|
required=True) |
|
|
|
service_state = fields.Selection( |
|
|
|
[('draft', 'Draft'), ('assigned', 'Assigned'), |
|
|
|
('completed', 'Completed'), ('returned', 'Returned'), |
|
|
|
('not_solved', 'Not solved')], |
|
|
|
string='Service Status', default='draft', track_visibility='always') |
|
|
|
|
|
|
|
complaints_tree = fields.One2many('mobile.complaint.tree', 'complaint_id', string='Complaints Tree') |
|
|
|
complaints_tree = fields.One2many('mobile.complaint.tree', 'complaint_id', |
|
|
|
string='Complaints Tree') |
|
|
|
|
|
|
|
product_order_line = fields.One2many('product.order.line', 'product_order_id', string='Parts Order Lines') |
|
|
|
product_order_line = fields.One2many('product.order.line', |
|
|
|
'product_order_id', |
|
|
|
string='Parts Order Lines') |
|
|
|
|
|
|
|
internal_notes = fields.Text(string="Internal notes") |
|
|
|
invoice_count = fields.Integer(compute='_invoice_count', string='# Invoice', copy=False) |
|
|
|
invoice_ids = fields.Many2many("account.move", string='Invoices', compute="_get_invoiced", readonly=True, |
|
|
|
invoice_count = fields.Integer(compute='_invoice_count', string='# Invoice', |
|
|
|
copy=False) |
|
|
|
invoice_ids = fields.Many2many("account.move", string='Invoices', |
|
|
|
compute="_get_invoiced", readonly=True, |
|
|
|
copy=False) |
|
|
|
|
|
|
|
first_payment_inv = fields.Many2one('account.move', copy=False) |
|
|
|
|
|
|
|
first_invoice_created = fields.Boolean(string="First Invoice Created", invisible=True, copy=False) |
|
|
|
first_invoice_created = fields.Boolean(string="First Invoice Created", |
|
|
|
invisible=True, copy=False) |
|
|
|
|
|
|
|
journal_type = fields.Many2one('account.journal', 'Journal', invisible=True, |
|
|
|
default=lambda self: self.env['account.journal'].search([('code', '=', 'SERV')])) |
|
|
|
default=lambda self: self.env[ |
|
|
|
'account.journal'].search( |
|
|
|
[('code', '=', 'SERV')])) |
|
|
|
|
|
|
|
company_id = fields.Many2one('res.company', 'Company', |
|
|
|
default=lambda self: self.env['res.company']._company_default_get('mobile.service')) |
|
|
|
default=lambda self: self.env[ |
|
|
|
'res.company']._company_default_get( |
|
|
|
'mobile.service')) |
|
|
|
|
|
|
|
@api.model |
|
|
|
def _default_picking_transfer(self): |
|
|
|
"""To get the default picking transfers""" |
|
|
|
type_obj = self.env['stock.picking.type'] |
|
|
|
company_id = self.env.context.get('company_id') or self.env.user.company_id.id |
|
|
|
types = type_obj.search([('code', '=', 'outgoing'), ('warehouse_id.company_id', '=', company_id)], limit=1) |
|
|
|
company_id = self.env.context.get( |
|
|
|
'company_id') or self.env.user.company_id.id |
|
|
|
types = type_obj.search([('code', '=', 'outgoing'), |
|
|
|
('warehouse_id.company_id', '=', company_id)], |
|
|
|
limit=1) |
|
|
|
if not types: |
|
|
|
types = type_obj.search([('code', '=', 'outgoing'), ('warehouse_id', '=', False)]) |
|
|
|
types = type_obj.search( |
|
|
|
[('code', '=', 'outgoing'), ('warehouse_id', '=', False)]) |
|
|
|
return types[:4] |
|
|
|
|
|
|
|
stock_picking_id = fields.Many2one('stock.picking', string="Picking Id") |
|
|
|
|
|
|
|
picking_transfer_id = fields.Many2one('stock.picking.type', 'Deliver To', required=True, |
|
|
|
picking_transfer_id = fields.Many2one('stock.picking.type', 'Deliver To', |
|
|
|
required=True, |
|
|
|
default=_default_picking_transfer, |
|
|
|
help="This will determine picking type of outgoing shipment") |
|
|
|
|
|
|
@ -105,22 +131,30 @@ class MobileServiceShop(models.Model): |
|
|
|
|
|
|
|
@api.onchange('return_date') |
|
|
|
def check_date(self): |
|
|
|
"""Check the return date and request date""" |
|
|
|
if self.return_date != False: |
|
|
|
return_date_string = datetime.strptime(str(self.return_date), "%Y-%m-%d") |
|
|
|
request_date_string = datetime.strptime(str(self.date_request), "%Y-%m-%d") |
|
|
|
return_date_string = datetime.strptime(str(self.return_date), |
|
|
|
"%Y-%m-%d") |
|
|
|
request_date_string = datetime.strptime(str(self.date_request), |
|
|
|
"%Y-%m-%d") |
|
|
|
if return_date_string < request_date_string: |
|
|
|
raise UserError("Return date should be greater than requested date") |
|
|
|
raise UserError( |
|
|
|
"Return date should be greater than requested date") |
|
|
|
|
|
|
|
def approve(self): |
|
|
|
"""assigning the Service Request to the corresponding user""" |
|
|
|
self.service_state = 'assigned' |
|
|
|
|
|
|
|
def complete(self): |
|
|
|
"""Mark the service request as completed""" |
|
|
|
self.service_state = 'completed' |
|
|
|
|
|
|
|
def return_to(self): |
|
|
|
"""The service request is returned to the client""" |
|
|
|
self.service_state = 'returned' |
|
|
|
|
|
|
|
def not_solved(self): |
|
|
|
"""Mark the service request as not solved""" |
|
|
|
self.service_state = 'not_solved' |
|
|
|
|
|
|
|
def action_send_mail(self): |
|
|
@ -130,11 +164,13 @@ class MobileServiceShop(models.Model): |
|
|
|
self.ensure_one() |
|
|
|
ir_model_data = self.env['ir.model.data'] |
|
|
|
try: |
|
|
|
template_id = ir_model_data._xmlid_lookup('mobile_service_shop.email_template_mobile_service')[2] |
|
|
|
template_id = ir_model_data._xmlid_lookup( |
|
|
|
'mobile_service_shop.email_template_mobile_service')[2] |
|
|
|
except ValueError: |
|
|
|
template_id = False |
|
|
|
try: |
|
|
|
compose_form_id = ir_model_data._xmlid_lookup('mail.email_compose_message_wizard_form')[2] |
|
|
|
compose_form_id = ir_model_data._xmlid_lookup( |
|
|
|
'mail.email_compose_message_wizard_form')[2] |
|
|
|
except ValueError: |
|
|
|
compose_form_id = False |
|
|
|
ctx = { |
|
|
@ -156,13 +192,13 @@ class MobileServiceShop(models.Model): |
|
|
|
} |
|
|
|
|
|
|
|
def return_advance(self): |
|
|
|
inv_obj = self.env['account.move'].search([('invoice_origin', '=', self.name)]) |
|
|
|
inv_obj = self.env['account.move'].search( |
|
|
|
[('invoice_origin', '=', self.name)]) |
|
|
|
inv_ids = [] |
|
|
|
for each in inv_obj: |
|
|
|
inv_ids.append(each.id) |
|
|
|
view_id = self.env.ref('account.view_move_form').id |
|
|
|
|
|
|
|
|
|
|
|
if inv_ids: |
|
|
|
if len(inv_ids) <= 1: |
|
|
|
value = { |
|
|
@ -189,28 +225,34 @@ class MobileServiceShop(models.Model): |
|
|
|
raise UserError("No invoice created") |
|
|
|
|
|
|
|
def _invoice_count(self): |
|
|
|
invoice_ids = self.env['account.move'].search([('invoice_origin', '=', self.name)]) |
|
|
|
"""Calculating the number of invoices""" |
|
|
|
invoice_ids = self.env['account.move'].search( |
|
|
|
[('invoice_origin', '=', self.name)]) |
|
|
|
self.invoice_count = len(invoice_ids) |
|
|
|
|
|
|
|
@api.model |
|
|
|
def create(self, vals): |
|
|
|
print(self.env.user.company_id) |
|
|
|
"""Creating sequence""" |
|
|
|
if 'company_id' in vals: |
|
|
|
vals['name'] = self.env['ir.sequence'].with_context(force_company=self.env.user.company_id.id).next_by_code( |
|
|
|
vals['name'] = self.env['ir.sequence'].with_context( |
|
|
|
force_company=self.env.user.company_id.id).next_by_code( |
|
|
|
'mobile.service') or _('New') |
|
|
|
else: |
|
|
|
vals['name'] = self.env['ir.sequence'].next_by_code('mobile.service') or _('New') |
|
|
|
vals['name'] = self.env['ir.sequence'].next_by_code( |
|
|
|
'mobile.service') or _('New') |
|
|
|
vals['service_state'] = 'draft' |
|
|
|
return super(MobileServiceShop, self).create(vals) |
|
|
|
|
|
|
|
def unlink(self): |
|
|
|
"""Supering the unlink function""" |
|
|
|
for i in self: |
|
|
|
if i.service_state != 'draft': |
|
|
|
raise UserError(_('You cannot delete an assigned service request')) |
|
|
|
raise UserError( |
|
|
|
_('You cannot delete an assigned service request')) |
|
|
|
return super(MobileServiceShop, self).unlink() |
|
|
|
|
|
|
|
def action_invoice_create_wizard(self): |
|
|
|
|
|
|
|
"""opening a wizard to create invoice""" |
|
|
|
return { |
|
|
|
'name': _('Create Invoice'), |
|
|
|
'view_mode': 'form', |
|
|
@ -230,18 +272,20 @@ class MobileServiceShop(models.Model): |
|
|
|
'origin': self.name, |
|
|
|
'location_dest_id': self.person_name.property_stock_customer.id, |
|
|
|
'location_id': self.picking_transfer_id.default_location_src_id.id, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
picking = self.env['stock.picking'].create(pick) |
|
|
|
self.stock_picking_id = picking.id |
|
|
|
self.picking_count = len(picking) |
|
|
|
moves = order.filtered( |
|
|
|
lambda r: r.product_id.type in ['product', 'consu'])._create_stock_moves_transfer(picking) |
|
|
|
lambda r: r.product_id.type in ['product', |
|
|
|
'consu'])._create_stock_moves_transfer( |
|
|
|
picking) |
|
|
|
move_ids = moves._action_confirm() |
|
|
|
move_ids._action_assign() |
|
|
|
if order.product_uom_qty < order.qty_stock_move: |
|
|
|
raise UserError(_('Used quantity is less than quantity stock move posted. ')) |
|
|
|
raise UserError( |
|
|
|
_('Used quantity is less than quantity stock move posted. ')) |
|
|
|
if flag != 1: |
|
|
|
raise UserError(_('Nothing to post stock move')) |
|
|
|
if flag != 1: |
|
|
@ -259,7 +303,8 @@ class MobileServiceShop(models.Model): |
|
|
|
'target': 'current', |
|
|
|
'context': ctx |
|
|
|
} |
|
|
|
invoice_ids = self.env['account.move'].search([('invoice_origin', '=', self.name)]) |
|
|
|
invoice_ids = self.env['account.move'].search( |
|
|
|
[('invoice_origin', '=', self.name)]) |
|
|
|
inv_ids = [] |
|
|
|
for each in invoice_ids: |
|
|
|
inv_ids.append(each.id) |
|
|
@ -274,38 +319,6 @@ class MobileServiceShop(models.Model): |
|
|
|
action['view_mode'] = 'tree,form' |
|
|
|
action['domain'] = [('id', 'in', inv_ids)] |
|
|
|
return action |
|
|
|
# inv_obj = self.env['account.move'].search([('invoice_origin', '=', self.name)]) |
|
|
|
# inv_ids = [] |
|
|
|
# for each in inv_obj: |
|
|
|
# inv_ids.append(each.id) |
|
|
|
# view_id = self.env.ref('account.view_move_form').id |
|
|
|
# ctx = dict( |
|
|
|
# create=False, |
|
|
|
# ) |
|
|
|
# if inv_ids: |
|
|
|
# if len(inv_ids) <= 1: |
|
|
|
# value = { |
|
|
|
# 'view_mode': 'form', |
|
|
|
# 'res_model': 'account.move', |
|
|
|
# 'view_id': view_id, |
|
|
|
# 'type': 'ir.actions.act_window', |
|
|
|
# 'name': 'Invoice', |
|
|
|
# 'context': ctx, |
|
|
|
# 'res_id': inv_ids and inv_ids[0] |
|
|
|
# } |
|
|
|
# else: |
|
|
|
# value = { |
|
|
|
# 'domain': str([('id', 'in', inv_ids)]), |
|
|
|
# 'view_mode': 'tree,form', |
|
|
|
# 'res_model': 'account.move', |
|
|
|
# 'view_id': False, |
|
|
|
# 'type': 'ir.actions.act_window', |
|
|
|
# 'context': ctx, |
|
|
|
# 'name': 'Invoice', |
|
|
|
# 'res_id': inv_ids |
|
|
|
# } |
|
|
|
# |
|
|
|
# return value |
|
|
|
|
|
|
|
def get_ticket(self): |
|
|
|
self.ensure_one() |
|
|
@ -315,10 +328,12 @@ class MobileServiceShop(models.Model): |
|
|
|
time = pytz.utc.localize(datetime.now()).astimezone(tz) |
|
|
|
date_today = time.strftime("%Y-%m-%d %H:%M %p") |
|
|
|
else: |
|
|
|
date_today = datetime.strftime(datetime.now(), "%Y-%m-%d %I:%M:%S %p") |
|
|
|
date_today = datetime.strftime(datetime.now(), |
|
|
|
"%Y-%m-%d %I:%M:%S %p") |
|
|
|
complaint_text = "" |
|
|
|
description_text = "" |
|
|
|
complaint_id = self.env['mobile.complaint.tree'].search([('complaint_id', '=', self.id)]) |
|
|
|
complaint_id = self.env['mobile.complaint.tree'].search( |
|
|
|
[('complaint_id', '=', self.id)]) |
|
|
|
if complaint_id: |
|
|
|
for obj in complaint_id: |
|
|
|
complaint = obj.complaint_type_tree |
|
|
@ -347,7 +362,9 @@ class MobileServiceShop(models.Model): |
|
|
|
'model_name': self.model_name.mobile_brand_models, |
|
|
|
|
|
|
|
} |
|
|
|
return self.env.ref('mobile_service_shop.mobile_service_ticket').report_action(self, data=data) |
|
|
|
return self.env.ref( |
|
|
|
'mobile_service_shop.mobile_service_ticket').report_action(self, |
|
|
|
data=data) |
|
|
|
|
|
|
|
|
|
|
|
class MobileBrand(models.Model): |
|
|
@ -368,7 +385,9 @@ class MobileComplaintTypeTemplate(models.Model): |
|
|
|
_name = 'mobile.complaint.description' |
|
|
|
_rec_name = 'description' |
|
|
|
|
|
|
|
complaint_type_template = fields.Many2one('mobile.complaint', string="Complaint Type Template", required=True) |
|
|
|
complaint_type_template = fields.Many2one('mobile.complaint', |
|
|
|
string="Complaint Type Template", |
|
|
|
required=True) |
|
|
|
description = fields.Text(string="Complaint Description") |
|
|
|
|
|
|
|
|
|
|
@ -378,8 +397,10 @@ class MobileComplaintTree(models.Model): |
|
|
|
|
|
|
|
complaint_id = fields.Many2one('mobile.service') |
|
|
|
|
|
|
|
complaint_type_tree = fields.Many2one('mobile.complaint', string="Category", required=True) |
|
|
|
description_tree = fields.Many2one('mobile.complaint.description', string="Description", |
|
|
|
complaint_type_tree = fields.Many2one('mobile.complaint', string="Category", |
|
|
|
required=True) |
|
|
|
description_tree = fields.Many2one('mobile.complaint.description', |
|
|
|
string="Description", |
|
|
|
domain="[('complaint_type_template','=',complaint_type_tree)]") |
|
|
|
|
|
|
|
|
|
|
@ -387,7 +408,8 @@ class MobileBrandModels(models.Model): |
|
|
|
_name = 'brand.model' |
|
|
|
_rec_name = 'mobile_brand_models' |
|
|
|
|
|
|
|
mobile_brand_name = fields.Many2one('mobile.brand', string="Mobile Brand", required=True) |
|
|
|
mobile_brand_name = fields.Many2one('mobile.brand', string="Mobile Brand", |
|
|
|
required=True) |
|
|
|
mobile_brand_models = fields.Char(string="Model Name", required=True) |
|
|
|
image_medium = fields.Binary(string='image', store=True, attachment=True) |
|
|
|
|
|
|
@ -401,5 +423,3 @@ class MobileServiceTermsAndConditions(models.Model): |
|
|
|
|
|
|
|
def _find_id(self): |
|
|
|
self.terms_id = self.id or '' |
|
|
|
|
|
|
|
|
|
|
|