forked from Yaltik/golem
Ajout des test de cas de multiple facturation
This commit is contained in:
parent
9b086fef97
commit
bc8c6dbd58
@ -80,7 +80,6 @@ class GolemResourceReservation(models.Model):
|
|||||||
amount = product.standard_price
|
amount = product.standard_price
|
||||||
delta = fields.Datetime.from_string(reservation.date_stop) - \
|
delta = fields.Datetime.from_string(reservation.date_stop) - \
|
||||||
fields.Datetime.from_string(reservation.date_start)
|
fields.Datetime.from_string(reservation.date_start)
|
||||||
|
|
||||||
quantity = (delta.days * 24) + (delta.seconds/3600.0)
|
quantity = (delta.days * 24) + (delta.seconds/3600.0)
|
||||||
account_id = False
|
account_id = False
|
||||||
if not product:
|
if not product:
|
||||||
|
@ -33,48 +33,32 @@ class TestGolemResourceReservation(TransactionCase):
|
|||||||
self.resource = self.env['golem.resource'].create({
|
self.resource = self.env['golem.resource'].create({
|
||||||
'name': 'Resource',
|
'name': 'Resource',
|
||||||
'avaibility_start': '2018-01-01',
|
'avaibility_start': '2018-01-01',
|
||||||
'avaibility_stop': '2020-01-01'
|
|
||||||
})
|
|
||||||
self.resource_val = self.env['golem.resource'].create({
|
|
||||||
'name': 'Resource to validate',
|
|
||||||
'avaibility_start': '2018-01-01',
|
|
||||||
'avaibility_stop': '2020-01-01',
|
'avaibility_stop': '2020-01-01',
|
||||||
'validation_required': True
|
'availibility_24_7': True
|
||||||
})
|
})
|
||||||
|
|
||||||
self.timetable_obj = self.env['golem.resource.timetable']
|
|
||||||
|
|
||||||
timetable_data = {'resource_id': self.resource.id, 'weekday': '0',
|
|
||||||
'time_start': 8.0, 'time_stop': 12.0}
|
|
||||||
timetable_data2 = {'resource_id': self.resource.id, 'weekday': '1',
|
|
||||||
'availibility_24': True}
|
|
||||||
timetable_data3 = {'resource_id': self.resource.id, 'weekday': '2',
|
|
||||||
'time_start': 7.0, 'time_stop': 23.98}
|
|
||||||
timetable_data4 = {'resource_id': self.resource.id, 'weekday': '3',
|
|
||||||
'availibility_24': True}
|
|
||||||
|
|
||||||
self.timetable_obj.create(timetable_data)
|
|
||||||
self.timetable_obj.create(timetable_data2)
|
|
||||||
self.timetable_obj.create(timetable_data3)
|
|
||||||
self.timetable_obj.create(timetable_data4)
|
|
||||||
|
|
||||||
timetable_data['resource_id'] = self.resource_val.id
|
|
||||||
self.timetable_obj.create(timetable_data)
|
|
||||||
|
|
||||||
self.partner = self.env['res.partner'].create({'firstname': 'John',
|
self.partner = self.env['res.partner'].create({'firstname': 'John',
|
||||||
'lastname': 'DOE',
|
'lastname': 'DOE',
|
||||||
'is_company': False})
|
'is_company': False})
|
||||||
|
self.partner2 = self.env['res.partner'].create({'firstname': 'John',
|
||||||
|
'lastname': 'DOE',
|
||||||
|
'is_company': False})
|
||||||
self.data = {
|
self.data = {
|
||||||
'resource_id': self.resource.id,
|
'resource_id': self.resource.id,
|
||||||
'date_start': '2018-02-05 11:00:00', # is monday
|
'date_start': '2018-02-05 11:00:00', # is monday
|
||||||
'date_stop': '2018-02-05 12:00:00',
|
'date_stop': '2018-02-05 12:00:00',
|
||||||
'partner_id': self.partner.id
|
'partner_id': self.partner.id
|
||||||
}
|
}
|
||||||
|
self.data2 = {
|
||||||
|
'resource_id': self.resource.id,
|
||||||
|
'date_start': '2018-03-05 11:00:00', # is monday
|
||||||
|
'date_stop': '2018-03-05 12:00:00',
|
||||||
|
'partner_id': self.partner2.id
|
||||||
|
}
|
||||||
self.res_obj = self.env['golem.resource.reservation']
|
self.res_obj = self.env['golem.resource.reservation']
|
||||||
|
|
||||||
|
|
||||||
def test_reservation_invoice_single(self):
|
def test_single_reservation_invoice(self):
|
||||||
""" Test reservation bases """
|
""" Test reservation bases """
|
||||||
reservation = self.res_obj.create(self.data)
|
reservation = self.res_obj.create(self.data)
|
||||||
self.assertEqual(reservation.state, 'draft')
|
self.assertEqual(reservation.state, 'draft')
|
||||||
@ -94,9 +78,32 @@ class TestGolemResourceReservation(TransactionCase):
|
|||||||
'product_tmpl_id': self.env.ref('product.product_product_5').id})
|
'product_tmpl_id': self.env.ref('product.product_product_5').id})
|
||||||
reservation.create_invoice()
|
reservation.create_invoice()
|
||||||
self.assertTrue(reservation.invoice_id)
|
self.assertTrue(reservation.invoice_id)
|
||||||
self.assertEqual(reservation.invoicing_state,"draft")
|
self.assertEqual(reservation.invoicing_state, "draft")
|
||||||
|
|
||||||
"""
|
def test_multiple_reservation_in(self):
|
||||||
self.assertEqual(reservation.state, 'validated')
|
""" Test Multiple Reservation Invoices """
|
||||||
reservation.create_invoice()
|
reservation_1 = self.res_obj.create(self.data)
|
||||||
self.assertTrue(reservation.invoice_id)"""
|
reservation_2 = self.res_obj.create(self.data2)
|
||||||
|
#reservations = [reservation_1, reservation_2]
|
||||||
|
reservation_1.state_confirm()
|
||||||
|
reservation_2.state_confirm()
|
||||||
|
self.assertEqual(reservation_1.state, "validated")
|
||||||
|
self.assertEqual(reservation_2.state, "validated")
|
||||||
|
reservation_1.resource_id.write({
|
||||||
|
'product_tmpl_id': self.env.ref('product.product_product_5').id})
|
||||||
|
reservation_2.resource_id.write({
|
||||||
|
'product_tmpl_id': self.env.ref('product.product_product_5').id})
|
||||||
|
wizard = self.env['golem.reservation.invoice.wizard'].create({
|
||||||
|
'reservation_ids': [(4, reservation_1.id, 0), (4, reservation_2.id, 0)]})
|
||||||
|
self.assertTrue(wizard.reservation_ids)
|
||||||
|
self.assertEqual(wizard.reservation_ids[0], reservation_2)
|
||||||
|
self.assertEqual(wizard.reservation_ids[1], reservation_1)
|
||||||
|
#try to create invoice for to different client
|
||||||
|
with self.assertRaises(UserError) as err:
|
||||||
|
wizard.create_invoices()
|
||||||
|
self.assertIn(u'group reservations of multiple clients in the same', err.exception.args[0])
|
||||||
|
#fixing the same client for both reservation
|
||||||
|
reservation_2.write({'partner_id': self.partner.id})
|
||||||
|
wizard.create_invoices()
|
||||||
|
self.assertTrue(reservation_1.invoice_id)
|
||||||
|
self.assertTrue(reservation_2.invoice_id)
|
||||||
|
@ -53,14 +53,25 @@ class GolemReservationInvoiceWizard(models.TransientModel):
|
|||||||
lines = []
|
lines = []
|
||||||
|
|
||||||
for reservation in self.reservation_ids:
|
for reservation in self.reservation_ids:
|
||||||
|
if reservation.state != "validated":
|
||||||
|
raise UserError(
|
||||||
|
_("The reservation '%s' is not validated, please validate it before \
|
||||||
|
creating invoice") % reservation.name)
|
||||||
|
product = reservation.resource_id.product_tmpl_id
|
||||||
|
if not product:
|
||||||
|
raise UserError(
|
||||||
|
_("There is no product linked to resource : '%s', you can't invoice \
|
||||||
|
reservation with no product linked") % (reservation.resource_id.name,))
|
||||||
if partner_id != reservation.partner_id:
|
if partner_id != reservation.partner_id:
|
||||||
raise ValidationError(
|
raise UserError(
|
||||||
_("You can't group reservations of multiple clients in the same \
|
_("You can't group reservations of multiple clients in the same \
|
||||||
invoice, please remove inadequate reservations"))
|
invoice, please remove inadequate reservations"))
|
||||||
|
|
||||||
product = reservation.resource_id.product_tmpl_id
|
|
||||||
amount = product.standard_price
|
amount = product.standard_price
|
||||||
quantity = reservation.hour_stop - reservation.hour_start
|
delta = fields.Datetime.from_string(reservation.date_stop) - \
|
||||||
|
fields.Datetime.from_string(reservation.date_start)
|
||||||
|
|
||||||
|
quantity = (delta.days * 24) + (delta.seconds/3600.0)
|
||||||
lines.append((0, 0, {
|
lines.append((0, 0, {
|
||||||
'name': reservation.resource_id.name,
|
'name': reservation.resource_id.name,
|
||||||
#'origin': ,
|
#'origin': ,
|
||||||
|
Loading…
Reference in New Issue
Block a user