Reservations report #20

Manually merged
fabien merged 7 commits from youssef/GOLEM:resource_report into master 2018-05-25 16:59:04 +02:00
2 changed files with 22 additions and 8 deletions
Showing only changes of commit 1398cb945d - Show all commits

View File

@ -44,10 +44,17 @@ class GolemResevationReport(models.AbstractModel):
lst = reservations.mapped('resource_id.name') lst = reservations.mapped('resource_id.name')
return lst return lst
def get_client_color(self, client_id): def get_client_color(self, partner_number):
client_id *= 777777 colors = ['#FFFF5B', '#81EC54', '#47C8C8', '#FB5A66', '#E8E750',
color = "#0" + str(client_id) '#CF4ACF', '#9655D2', '#FFA15B', '#5F68D5', '#60E652']
color = color[:7] color = "#000000"
if partner_number < 10:
color = colors[partner_number]
else:
red = randint(128, 255)
green = randint(128, 255)
blue = randint(128, 255)
color = "#" +hex(red)[2:]+hex(green)[2:]+hex(blue)[2:]
return color return color
def get_data(self, data): def get_data(self, data):
@ -56,16 +63,23 @@ class GolemResevationReport(models.AbstractModel):
('date_stop', '<', data['date_stop']), ('date_stop', '<', data['date_stop']),
('resource_id', 'in', data['resource_ids'])] ('resource_id', 'in', data['resource_ids'])]
reservations = self.env['golem.resource.reservation'].search(domain, order='date_start') reservations = self.env['golem.resource.reservation'].search(domain, order='date_start')
partner_ids = reservations.mapped('partner_id.id')
partner_colors = {}
partner_number = 0
for partner_id in partner_ids:
partner_colors[str(partner_id)] = self.get_client_color(partner_number)
partner_number +=1
res = {} res = {}
for reservation in reservations: for reservation in reservations:
res = { res = {
'name': reservation.name, 'name': reservation.name,
'resource_name': reservation.resource_id.name, 'resource_name': reservation.resource_id.name,
'client': reservation.partner_id.name, 'client': reservation.partner_id.name,
'client_id': self.get_client_color(reservation.partner_id.id),
'date_start': reservation.date_start, 'date_start': reservation.date_start,
'date_stop': reservation.date_stop, 'date_stop': reservation.date_stop,
'day_start': reservation.day_start 'day_start': reservation.day_start,
'bgcolor': partner_colors[str(reservation.partner_id.id)]
} }
lst.append(res) lst.append(res)
return lst return lst

View File

@ -45,10 +45,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<td><span t-esc="resource"/></td> <td><span t-esc="resource"/></td>
<t t-foreach="get_data" t-as="data"> <t t-foreach="get_data" t-as="data">
<t t-if="data['resource_name']==resource"> <t t-if="data['resource_name']==resource">
<td t-attf-style="background-color:{{data['client_id']}}!important;"> <td t-attf-style="background-color:{{data['bgcolor']}}!important;">
<b>Date :</b><span t-esc="data['day_start']"/><br/> <b>Date :</b><span t-esc="data['day_start']"/><br/>
<b>On behalf of :</b><span t-esc="data['client']"/><br/> <b>On behalf of :</b><span t-esc="data['client']"/><br/>
<b>client_id :</b><span t-esc="data['client_id']"/><br/> <b>client_id :</b><span t-esc="data['bgcolor']"/><br/>
</td> </td>
</t> </t>
</t> </t>