Skip to content

Commit

Permalink
[ADD] Add checkbox to choose all-day duration, and change invoicing
Browse files Browse the repository at this point in the history
  • Loading branch information
kryskool committed Feb 21, 2016
1 parent d52c9d6 commit 7734645
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
31 changes: 26 additions & 5 deletions crm_intervention.py
Expand Up @@ -138,6 +138,8 @@ def _get_default_email_cc(self, cr, uid, context=None):
'duration_effective': fields.float(
'Effective duration',
help='Indicate real time to do the intervention.'),
'alldays_planned': fields.boolean('All day planned', help='All-day intervention planned'),
'alldays_effective': fields.boolean('All day effective', help='All-day intervention effective'),
'partner_id': fields.many2one(
'res.partner', 'Customer',
change_default=True, select=True),
Expand Down Expand Up @@ -195,6 +197,8 @@ def _get_default_email_cc(self, cr, uid, context=None):
c: s.pool.get('res.company')._company_default_get(
cr, uid, 'crm.helpdesk', context=c),
'priority': lambda *a: crm.AVAILABLE_PRIORITIES[2][0],
'alldays_planned': False,
'alldays_effective': False,
}

def onchange_partner_intervention_id(self, cr, uid, ids, part):
Expand Down Expand Up @@ -394,6 +398,9 @@ def generate_analytic_line(self, cr, uid, ids, context=None):
raise orm.except_orm(_('Error'), _('Product to invoice is necessary'))
if not inter.contract_id:
raise orm.except_orm(_('Error'), _('Contract is necessary'))
if inter.product_id.standard_price < 0.1:
raise orm.except_orm(_('Error'),
_('Please define a cost price for the product %s') % inter.product_id.name)

# Find the analytic journal from the employe
emp_obj = self.pool['hr.employee']
Expand All @@ -403,7 +410,21 @@ def generate_analytic_line(self, cr, uid, ids, context=None):

emp = emp_obj.browse(cr, uid, emp_ids[0], context=context)

# TODO invoice journee
if inter.alldays_effective:
q = self.pool['product.uom']._compute_price(
cr, uid, inter.product_id.uom_id.id, inter.product_id.standard_price,
inter.section_id.unit_day_id.id)
amount = q * -1
unit_amount = 1.0
unit = inter.section_id.unit_day_id.id
else:
q = self.pool['product.uom']._compute_price(
cr, uid, inter.product_id.uom_id.id, inter.product_id.standard_price,
inter.section_id.unit_hour_id.id)
amount = (q * inter.duration_effective) * -1
unit_amount = inter.duration_effective
unit = inter.section_id.unit_hour_id.id

vals = {
'name': _('BI Num %s') % inter.number_request,
'account_id': inter.contract_id.id,
Expand All @@ -413,14 +434,14 @@ def generate_analytic_line(self, cr, uid, ids, context=None):
'ref': inter.name[:64],
'to_invoice': inter.contract_id.to_invoice.id,
'product_id': inter.product_id.id,
'unit_amount': inter.duration_effective,
'product_uom_id': inter.section_id.unit_hour_id.id,
'amount': inter.product_id.standard_price,
'unit_amount': unit_amount,
'product_uom_id': unit,
'amount': amount,
'general_account_id': inter.product_id.property_account_income.id,
}

line_id = self.pool['account.analytic.line'].create(cr, uid, vals, context=context)
inter.write({'analytic_line_id': line_id}, context=context)
inter.write({'analytic_line_id': line_id, 'state': 'done'}, context=context)

return True

Expand Down
22 changes: 14 additions & 8 deletions crm_intervention_view.xml
Expand Up @@ -58,7 +58,8 @@
<field name="partner_id" on_change="onchange_partner_intervention_id(partner_id)" required="1" attrs="{'readonly':[('state','=','done')]}"/>
<field name="user_id" string="Planned for" colspan="1" attrs="{'readonly':[('state','=','done')]}"/>
<newline/>
<field name="product_id"/>
<field name="product_id" attrs="{'readonly':[('state','=','done')]}"/>
<field name="priority" string="Priority" attrs="{'readonly':[('state','=','done')]}"/>
</group>
<notebook colspan="4">
<page string="General">
Expand All @@ -81,19 +82,24 @@
attrs="{'readonly':[('state','=','done')]}"/>
</page>
<page string="Before Intervention">
<group colspan="4">
<group colspan="4" col="4">
<field name="date_planned_start" colspan="1" attrs="{'readonly':[('state','=','done')]}"/>
<field name="priority" string="Priority" attrs="{'readonly':[('state','=','done')]}"/>
<field name="date_planned_end" on_change="onchange_planned_end_date(date_planned_end, date_planned_start)" colspan="1" attrs="{'readonly':[('state','=','done')]}"/>
<field name="duration_planned" on_change="onchange_planned_duration(duration_planned, date_planned_start)" widget="float_time" attrs="{'readonly':[('state','=','done')]}"/>
<field name="alldays_planned" attrs="{'readonly':[('state','=','done')]}"/>
<field name="duration_planned" on_change="onchange_planned_duration(duration_planned, date_planned_start)" widget="float_time"
attrs="{'readonly':['|', ('state','=','done'),('alldays_planned','=',True)]}"/>
<field name="date_planned_end" on_change="onchange_planned_end_date(date_planned_end, date_planned_start)" colspan="1"
attrs="{'readonly':['|', ('state','=','done'),('alldays_planned','=',True)]}"/>
<field name="intervention_todo" nolabel="1" colspan="4" required="0" attrs="{'readonly':[('state','=','done')]}"/>
</group>
</page>
<page string="After Intervention">
<group colspan="4">
<group colspan="4" col="4">
<field name="date_effective_start" colspan="1" attrs="{'readonly':[('state','=','done')]}"/>
<field name="duration_effective" on_change="onchange_effective_duration(duration_effective, date_effective_start)" widget="float_time" attrs="{'readonly':[('state','=','done')]}"/>
<field name="date_effective_end" on_change="onchange_effective_end_date(date_effective_end, date_effective_start)" colspan="1" attrs="{'readonly':[('state','=','done')]}"/>
<field name="alldays_effective" attrs="{'readonly':[('state','=','done')]}"/>
<field name="duration_effective" on_change="onchange_effective_duration(duration_effective, date_effective_start)" widget="float_time"
attrs="{'readonly':['|',('state','=','done'),('alldays_effective','=',True)]}"/>
<field name="date_effective_end" on_change="onchange_effective_end_date(date_effective_end, date_effective_start)" colspan="1"
attrs="{'readonly':['|',('state','=','done'),('alldays_effective','=',True)]}"/>
<field name="categ_id" context="{'object_id':'crm.intervention'}" attrs="{'readonly':[('state','=','done')]}"/>
<field name="description" string="Customer" colspan="4" nolabel="1" attrs="{'readonly':[('state','=','done')]}"/>
</group>
Expand Down

0 comments on commit 7734645

Please sign in to comment.