diff --git a/stock_card_report_value/reports/stock_card_report.py b/stock_card_report_value/reports/stock_card_report.py index 0255fbe..7a3443a 100644 --- a/stock_card_report_value/reports/stock_card_report.py +++ b/stock_card_report_value/reports/stock_card_report.py @@ -55,3 +55,7 @@ def _compute_results(self): stock_card_results = self._cr.dictfetchall() ReportLine = self.env["stock.card.view"] self.results = [ReportLine.new(line).id for line in stock_card_results] + + def _get_initial_value(self, product_line): + value = sum(product_line.mapped("value")) + return value diff --git a/stock_card_report_value/reports/stock_card_report.xml b/stock_card_report_value/reports/stock_card_report.xml index a0907f7..f68548d 100644 --- a/stock_card_report_value/reports/stock_card_report.xml +++ b/stock_card_report_value/reports/stock_card_report.xml @@ -3,8 +3,30 @@ id="report_stock_card_report_base" inherit_id="stock_card_report.report_stock_card_report_base" > - + + + +
+
+ +
+
+ + + + + + @@ -14,6 +36,8 @@ >
Value
+
Cumulative Value
+
Unit Cost
@@ -25,6 +49,14 @@
+
+ +
+
+ +
diff --git a/stock_card_report_value/reports/stock_card_report_xlsx.py b/stock_card_report_value/reports/stock_card_report_xlsx.py index 4a4aa2b..b00ef4e 100644 --- a/stock_card_report_value/reports/stock_card_report_xlsx.py +++ b/stock_card_report_value/reports/stock_card_report_xlsx.py @@ -43,9 +43,33 @@ def _get_ws_params(self, wb, data, product): initial_template = { "1_ref": { "data": {"value": "Initial", "format": FORMATS["format_tcell_center"]}, - "colspan": 5, + "colspan": 3, }, - "3_balance": { + "2_initial_value": { + "data": { + "value": self._render("initial_value"), + "format": FORMATS["format_tcell_amount_right"], + } + }, + "3_space": { + "data": { + "value": "", + "format": FORMATS["format_tcell_center"], + } + }, + "4_space": { + "data": { + "value": "", + "format": FORMATS["format_tcell_center"], + } + }, + "5_space": { + "data": { + "value": "", + "format": FORMATS["format_tcell_center"], + } + }, + "6_balance": { "data": { "value": self._render("balance"), "format": FORMATS["format_tcell_amount_right"], @@ -74,17 +98,27 @@ def _get_ws_params(self, wb, data, product): "data": {"value": self._render("value")}, "width": 25, }, - "4_input": { + "4_cumulative_value": { + "header": {"value": "Cumulative Value"}, + "data": {"value": self._render("cumulative_value")}, + "width": 25, + }, + "5_unit_cost": { + "header": {"value": "Unit Cost"}, + "data": {"value": self._render("unit_cost")}, + "width": 25, + }, + "6_input": { "header": {"value": "In"}, "data": {"value": self._render("input")}, "width": 25, }, - "5_output": { + "7_output": { "header": {"value": "Out"}, "data": {"value": self._render("output")}, "width": 25, }, - "6_balance": { + "8_balance": { "header": {"value": "Balance"}, "data": {"value": self._render("balance")}, "width": 25, @@ -149,12 +183,18 @@ def _stock_card_report(self, wb, ws, ws_params, data, objects, product): balance = objects._get_initial( objects.results.filtered(lambda l: l.product_id == product and l.is_initial) ) + cumulative_value = objects._get_initial_value( + objects.results.filtered(lambda l: l.product_id == product and l.is_initial) + ) row_pos = self._write_line( ws, row_pos, ws_params, col_specs_section="data", - render_space={"balance": balance}, + render_space={ + "balance": balance, + "initial_value": cumulative_value, + }, col_specs="col_specs_initial", wanted_list="wanted_list_initial", ) @@ -163,6 +203,8 @@ def _stock_card_report(self, wb, ws, ws_params, data, objects, product): ) for line in product_lines: balance += line.product_in - line.product_out + cumulative_value += line.value + unit_cost = line.value / abs(line.product_in - line.product_out) row_pos = self._write_line( ws, row_pos, @@ -172,6 +214,8 @@ def _stock_card_report(self, wb, ws, ws_params, data, objects, product): "date": line.date or "", "reference": line.display_name or "", "value": line.value or 0, + "cumulative_value": cumulative_value, + "unit_cost": unit_cost, "input": line.product_in or 0, "output": line.product_out or 0, "balance": balance,