Skip to content

Commit

Permalink
[stock_card_report_value] Unit Cost
Browse files Browse the repository at this point in the history
Acumulative Value
  • Loading branch information
mikevhe18 committed Sep 30, 2023
1 parent ccaa39a commit 8013604
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 7 deletions.
4 changes: 4 additions & 0 deletions stock_card_report_value/reports/stock_card_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 33 additions & 1 deletion stock_card_report_value/reports/stock_card_report.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,30 @@
id="report_stock_card_report_base"
inherit_id="stock_card_report.report_stock_card_report_base"
>
<xpath expr="//div[@class='act_as_row lines']/div[3]" position="after">
<xpath expr="//div[@class='act_as_row lines']" position="before">
<t
t-set="initial_value"
t-value="o._get_initial_value(o.results.filtered(lambda l: l.product_id == product and l.is_initial))"
/>
</xpath>
<xpath expr="//div[@class='act_as_row lines']/div[2]" position="after">
<div class="act_as_cell" />
<div class="act_as_cell right">
<t t-esc="'{0:,.3f}'.format(initial_value)" />
</div>
<div class="act_as_cell" />
</xpath>
<xpath expr="//div[@class='act_as_row lines']" position="after">
<t t-set="cumulative_value" t-value="initial_value" />
</xpath>
<xpath
expr="//t[@t-call='stock_card_report.report_stock_card_lines']"
position="before"
>
<t
t-set="cumulative_value"
t-value="cumulative_value + product_line.value"
/>
</xpath>
</template>

Expand All @@ -14,6 +36,8 @@
>
<xpath expr="//div[1]/div[1]/div[2]" position="after">
<div class="act_as_cell">Value</div>
<div class="act_as_cell">Cumulative Value</div>
<div class="act_as_cell">Unit Cost</div>
</xpath>
</template>

Expand All @@ -25,6 +49,14 @@
<div class="act_as_cell right">
<t t-esc="'{0:,.3f}'.format(product_line.value)" />
</div>
<div class="act_as_cell right">
<t t-esc="'{0:,.3f}'.format(cumulative_value)" />
</div>
<div class="act_as_cell right">
<t
t-esc="'{0:,.3f}'.format(product_line.value / abs(product_line.product_in - product_line.product_out))"
/>
</div>
</xpath>
</template>

Expand Down
56 changes: 50 additions & 6 deletions stock_card_report_value/reports/stock_card_report_xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
)
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 8013604

Please sign in to comment.