|
@ -1,5 +1,6 @@ |
|
|
# -*- coding: utf-8 -*- |
|
|
# -*- coding: utf-8 -*- |
|
|
"""Event Management""" |
|
|
"""Event Management""" |
|
|
|
|
|
import mailbox |
|
|
################################################################################ |
|
|
################################################################################ |
|
|
# |
|
|
# |
|
|
# Cybrosys Technologies Pvt. Ltd. |
|
|
# Cybrosys Technologies Pvt. Ltd. |
|
@ -102,6 +103,9 @@ class EventManagement(models.Model): |
|
|
def action_event_confirm(self): |
|
|
def action_event_confirm(self): |
|
|
"""Button action to confirm""" |
|
|
"""Button action to confirm""" |
|
|
self.state = "confirm" |
|
|
self.state = "confirm" |
|
|
|
|
|
for lines in self.service_line_ids: |
|
|
|
|
|
if lines.state == 'pending': |
|
|
|
|
|
lines.is_pending = True |
|
|
|
|
|
|
|
|
def action_event_cancel(self): |
|
|
def action_event_cancel(self): |
|
|
"""Button action to cancel""" |
|
|
"""Button action to cancel""" |
|
@ -136,88 +140,94 @@ class EventManagement(models.Model): |
|
|
|
|
|
|
|
|
def action_event_invoice_create(self): |
|
|
def action_event_invoice_create(self): |
|
|
"""Button action to create related invoice""" |
|
|
"""Button action to create related invoice""" |
|
|
product_line = [] |
|
|
if self.service_line_ids.filtered(lambda x: x.state == 'pending'): |
|
|
payment_list = [] |
|
|
raise ValidationError(_('You can create the invoice only when all ' |
|
|
for line in self.service_line_ids: |
|
|
'services is Done')) |
|
|
if line.invoiced is False and line.state == "done": |
|
|
else: |
|
|
product_line.append({'product_id': line.related_product_id, |
|
|
product_line = [] |
|
|
'price_unit': line.amount}) |
|
|
payment_list = [] |
|
|
line.invoiced = True |
|
|
related_product = self.env.ref( |
|
|
if len(product_line) > 0: |
|
|
'event_management.catering_service_product').id |
|
|
invoice = self.env['account.move'] |
|
|
product_id = self.env['product.product'].browse(related_product) |
|
|
move_type = 'out_invoice' |
|
|
for line in self.service_line_ids: |
|
|
invoice = invoice.with_context(default_move_type=move_type) |
|
|
if line.invoiced is False and line.state == "done": |
|
|
journal_id = invoice._compute_journal_id() |
|
|
product_line.append({'product_id': product_id, |
|
|
company_id = self.env.user.company_id.id |
|
|
'price_unit': line.amount}) |
|
|
inv_obj = self.env['account.move'] |
|
|
line.invoiced = True |
|
|
partner = self.partner_id |
|
|
if len(product_line) > 0: |
|
|
for records in product_line: |
|
|
invoice = self.env['account.move'] |
|
|
product_id = records['product_id'] |
|
|
move_type = 'out_invoice' |
|
|
price_unit = records['price_unit'] |
|
|
invoice = invoice.with_context(default_move_type=move_type) |
|
|
if product_id.property_account_income_id.id: |
|
|
journal_id = invoice._compute_journal_id() |
|
|
income_account = product_id.property_account_income_id.id |
|
|
company_id = self.env.user.company_id.id |
|
|
elif product_id.categ_id.property_account_income_categ_id.id: |
|
|
inv_obj = self.env['account.move'] |
|
|
income_account = product_id.categ_id.property_account_income_categ_id.id |
|
|
partner = self.partner_id |
|
|
else: |
|
|
for records in product_line: |
|
|
raise UserError( |
|
|
product_id = records['product_id'] |
|
|
_('Please define income account for' |
|
|
price_unit = records['price_unit'] |
|
|
' this product: "%s" (id:%d).') % ( |
|
|
if product_id.property_account_income_id.id: |
|
|
product_id.name, product_id.id)) |
|
|
income_account = product_id.property_account_income_id.id |
|
|
|
|
|
elif product_id.categ_id.property_account_income_categ_id.id: |
|
|
|
|
|
income_account = product_id.categ_id.property_account_income_categ_id.id |
|
|
|
|
|
else: |
|
|
|
|
|
raise UserError( |
|
|
|
|
|
_('Please define income account for' |
|
|
|
|
|
' this product: "%s" (id:%d).') % ( |
|
|
|
|
|
product_id.name, product_id.id)) |
|
|
|
|
|
|
|
|
inv_line_data = { |
|
|
inv_line_data = { |
|
|
'name': self.name, |
|
|
'name': self.name, |
|
|
'account_id': income_account, |
|
|
'account_id': income_account, |
|
|
'price_unit': price_unit, |
|
|
'price_unit': price_unit, |
|
|
'quantity': 1, |
|
|
'quantity': 1, |
|
|
'product_id': product_id.id, |
|
|
'product_id': product_id.id, |
|
|
'product_uom_id': product_id.uom_id.id, |
|
|
'product_uom_id': product_id.uom_id.id, |
|
|
|
|
|
} |
|
|
|
|
|
payment_list.append((0, 0, inv_line_data)) |
|
|
|
|
|
inv_data = { |
|
|
|
|
|
'move_type': move_type, |
|
|
|
|
|
'ref': self.name, |
|
|
|
|
|
'bank_partner_id': partner.property_account_payable_id.id, |
|
|
|
|
|
'partner_id': partner.id, |
|
|
|
|
|
'payment_reference': self.name, |
|
|
|
|
|
'company_id': company_id, |
|
|
|
|
|
'invoice_line_ids': payment_list, |
|
|
|
|
|
} |
|
|
|
|
|
inv_id = inv_obj.create(inv_data) |
|
|
|
|
|
result = { |
|
|
|
|
|
'view_type': 'form', |
|
|
|
|
|
'res_model': 'account.move', |
|
|
|
|
|
'res_id': inv_id.id, |
|
|
|
|
|
'view_id': False, |
|
|
|
|
|
'view_mode': 'form', |
|
|
|
|
|
'type': 'ir.actions.act_window' |
|
|
} |
|
|
} |
|
|
payment_list.append((0, 0, inv_line_data)) |
|
|
self.state = "invoice" |
|
|
inv_data = { |
|
|
all_invoice_ids = self.invoice_ids.ids |
|
|
'move_type': move_type, |
|
|
all_invoice_ids.append(inv_id.id) |
|
|
'ref': self.name, |
|
|
self.update({'invoice_ids': all_invoice_ids, |
|
|
'bank_partner_id': partner.property_account_payable_id.id, |
|
|
'invoice_count': self.invoice_count + 1}) |
|
|
'partner_id': partner.id, |
|
|
return result |
|
|
'payment_reference': self.name, |
|
|
|
|
|
'company_id': company_id, |
|
|
|
|
|
'invoice_line_ids': payment_list, |
|
|
|
|
|
} |
|
|
|
|
|
inv_id = inv_obj.create(inv_data) |
|
|
|
|
|
result = { |
|
|
|
|
|
'view_type': 'form', |
|
|
|
|
|
'res_model': 'account.move', |
|
|
|
|
|
'res_id': inv_id.id, |
|
|
|
|
|
'view_id': False, |
|
|
|
|
|
'view_mode': 'form', |
|
|
|
|
|
'type': 'ir.actions.act_window' |
|
|
|
|
|
} |
|
|
|
|
|
self.state = "invoice" |
|
|
|
|
|
all_invoice_ids = self.invoice_ids.ids |
|
|
|
|
|
all_invoice_ids.append(inv_id.id) |
|
|
|
|
|
self.update({'invoice_ids': all_invoice_ids, |
|
|
|
|
|
'invoice_count': self.invoice_count + 1}) |
|
|
|
|
|
return result |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EventServiceLine(models.Model): |
|
|
class EventServiceLine(models.Model): |
|
|
"""Model to manage the service lines of the event management""" |
|
|
"""Model to manage the service lines of the event management""" |
|
|
_name = 'event.service.line' |
|
|
_name = 'event.service.line' |
|
|
|
|
|
|
|
|
service = fields.Selection([('', '')], string="Services", |
|
|
service_id = fields.Many2one('event.services', string="Services") |
|
|
required=True) |
|
|
|
|
|
event_id = fields.Many2one('event.management', string="Event") |
|
|
event_id = fields.Many2one('event.management', string="Event") |
|
|
date_from = fields.Datetime(string="Date from", required=True) |
|
|
date_from = fields.Datetime(string="Date from", required=True) |
|
|
date_to = fields.Datetime(string="Date to", required=True) |
|
|
date_to = fields.Datetime(string="Date to", required=True) |
|
|
amount = fields.Float(string="Amount", readonly=True) |
|
|
amount = fields.Float(string="Amount") |
|
|
state = fields.Selection([('done', 'Done'), ('pending', 'Pending')], |
|
|
state = fields.Selection([('done', 'Done'), ('pending', 'Pending')], |
|
|
string="State", default="pending", |
|
|
string="State") |
|
|
readonly=True) |
|
|
|
|
|
currency_id = fields.Many2one('res.currency', readonly=True, |
|
|
currency_id = fields.Many2one('res.currency', readonly=True, |
|
|
default=lambda self: |
|
|
default=lambda self: |
|
|
self.env.user.company_id.currency_id) |
|
|
self.env.user.company_id.currency_id) |
|
|
invoiced = fields.Boolean(string="Invoiced", readonly=True) |
|
|
invoiced = fields.Boolean(string="Invoiced", readonly=True) |
|
|
related_product_id = fields.Many2one('product.product', |
|
|
related_product_id = fields.Many2one('product.product', |
|
|
string="Related Product") |
|
|
string="Related Product") |
|
|
|
|
|
is_pending = fields.Boolean(string="Pending") |
|
|
|
|
|
|
|
|
_sql_constraints = [('event_supplier_unique', 'unique(event_id, service)', |
|
|
_sql_constraints = [('event_supplier_unique', 'unique(event_id, service)', |
|
|
'Duplication Of Service In The Service Lines ' |
|
|
'Duplication Of Service In The Service Lines ' |
|
@ -230,7 +240,13 @@ class EventServiceLine(models.Model): |
|
|
raise ValidationError(_('"Date to" cannot be set before ' |
|
|
raise ValidationError(_('"Date to" cannot be set before ' |
|
|
'"Date from".\n\n' |
|
|
'"Date from".\n\n' |
|
|
'Check the "Date from" and "Date to" ' |
|
|
'Check the "Date from" and "Date to" ' |
|
|
'of the "%s" service' % rec.service)) |
|
|
'of the "%s" service' % rec.service_id)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EventService(models.Model): |
|
|
|
|
|
_name = 'event.services' |
|
|
|
|
|
|
|
|
|
|
|
name = fields.Char(string='Services') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EventManagementType(models.Model): |
|
|
class EventManagementType(models.Model): |
|
|