|
12 | 12 | 'currency', |
13 | 13 | 'year', |
14 | 14 | 'month', |
15 | | - 'day' |
16 | 15 | ] |
17 | 16 |
|
18 | 17 |
|
@@ -52,19 +51,19 @@ def _make_cost_data(self, results): |
52 | 51 |
|
53 | 52 | self._check_required_fields(result) |
54 | 53 |
|
| 54 | + result['additional_info']['Account'] = result.get('account') |
| 55 | + |
55 | 56 | try: |
56 | 57 | data = { |
57 | 58 | 'cost': result['cost'], |
58 | | - 'currency': result['currency'], |
59 | 59 | 'usage_quantity': result.get('usage_quantity', 0), |
| 60 | + 'usage_type': result.get('usage_type'), |
| 61 | + 'usage_unit': result.get('usage_unit'), |
60 | 62 | 'provider': result.get('provider'), |
61 | 63 | 'region_code': result.get('region_code'), |
62 | 64 | 'product': result.get('product'), |
63 | | - 'account': str(result.get('account')), |
64 | | - 'usage_type': result.get('usage_type'), |
65 | 65 | 'resource': result.get('resource', ''), |
66 | | - 'resource_group': result.get('resource_group', ''), |
67 | | - 'billed_at': self._create_billed_at_format(result['year'], result['month'], result['day']), |
| 66 | + 'billed_date': f'{result["year"]}-{result["month"]}', |
68 | 67 | 'additional_info': result.get('additional_info', {}), |
69 | 68 | 'tags': result.get('tags', {}) |
70 | 69 | } |
@@ -111,24 +110,23 @@ def _change_result_by_field_mapper(self, result): |
111 | 110 | del result[actual_additional_field] |
112 | 111 | result[origin_field] = additional_info |
113 | 112 |
|
114 | | - if 'billed_at' in origin_field: |
115 | | - if self._check_billed_at(result): |
116 | | - result['billed_at'] = self._apply_parse_date(result[origin_field]) |
| 113 | + if 'billed_date' in origin_field: |
| 114 | + if self._check_billed_date(result): |
| 115 | + result['billed_date'] = self._apply_parse_date(result[origin_field]) |
117 | 116 | result['year'] = result[origin_field].year |
118 | 117 | result['month'] = result[origin_field].month |
119 | | - result['day'] = result[origin_field].day |
120 | 118 |
|
121 | 119 | return result |
122 | 120 |
|
123 | 121 | @staticmethod |
124 | | - def _check_billed_at(result): |
125 | | - if result['billed_at']: |
| 122 | + def _check_billed_date(result): |
| 123 | + if result['billed_date']: |
126 | 124 | return True |
127 | | - elif result.get('year') and result.get('month') and result.get('day'): |
| 125 | + elif result.get('year') and result.get('month'): |
128 | 126 | return False |
129 | 127 | else: |
130 | 128 | _LOGGER.error(f'[_is_not_empty_billed_at] billed_at is empty: {result}') |
131 | | - raise ERROR_EMPTY_BILLED_AT(result=result) |
| 129 | + raise ERROR_EMPTY_BILLED_DATE(result=result) |
132 | 130 |
|
133 | 131 | @staticmethod |
134 | 132 | def _apply_parse_date(date): |
@@ -172,7 +170,7 @@ def _check_required_fields(result): |
172 | 170 | raise ERROR_REQUIRED_PARAMETER(key=field) |
173 | 171 |
|
174 | 172 | @staticmethod |
175 | | - def _create_billed_at_format(year, month, day): |
176 | | - date = f'{year}-{month}-{day}' |
177 | | - billed_at_format = '%Y-%m-%d' |
| 173 | + def _create_billed_date_format(year, month): |
| 174 | + date = f'{year}-{month}' |
| 175 | + billed_at_format = '%Y-%m' |
178 | 176 | return datetime.strptime(date, billed_at_format) |
0 commit comments