Skip to content

Commit

Permalink
[IMP] stock_inventory_valuation_report: black, isort, prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
solo4games authored and aleuffre committed Jan 2, 2024
1 parent e1efe8a commit e6c3bbe
Show file tree
Hide file tree
Showing 13 changed files with 536 additions and 406 deletions.
6 changes: 6 additions & 0 deletions setup/stock_inventory_valuation_report/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
32 changes: 16 additions & 16 deletions stock_inventory_valuation_report/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'Stock Inventory Valuation Report',
'summary': 'Add report button on Inventory Valuation.',
'version': '12.0.1.1.2',
'category': 'Warehouse',
'website': 'https://github.com/OCA/stock-logistics-reporting',
'author': 'Ecosoft,Odoo Community Association (OCA)',
'license': 'AGPL-3',
'depends': [
'stock_account',
'report_xlsx_helper',
"name": "Stock Inventory Valuation Report",
"summary": "Add report button on Inventory Valuation.",
"version": "14.0.1.0.0",
"category": "Warehouse",
"website": "https://github.com/OCA/stock-logistics-reporting",
"author": "Ecosoft,Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": [
"stock_account",
"report_xlsx_helper",
],
'data': [
'data/paper_format.xml',
'data/report_data.xml',
'reports/stock_inventory_valuation_report.xml',
'wizard/stock_quantity_history_view.xml',
"data": [
"data/paper_format.xml",
"data/report_data.xml",
"reports/stock_inventory_valuation_report.xml",
"wizard/stock_quantity_history_view.xml",
],
'installable': True,
"installable": True,
}
4 changes: 2 additions & 2 deletions stock_inventory_valuation_report/data/paper_format.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<record id="paperformat_inventory_valuation_report" model="report.paperformat">
<field name="name">Inventory Valuation Report A4</field>
<field name="default" eval="True"/>
<field name="default" eval="True" />
<field name="format">A4</field>
<field name="page_height">0</field>
<field name="page_width">0</field>
Expand All @@ -11,7 +11,7 @@
<field name="margin_bottom">28</field>
<field name="margin_left">7</field>
<field name="margin_right">7</field>
<field name="header_line" eval="False"/>
<field name="header_line" eval="False" />
<field name="header_spacing">24</field>
<field name="dpi">90</field>
</record>
Expand Down
39 changes: 23 additions & 16 deletions stock_inventory_valuation_report/data/report_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,31 @@
<record id="action_stock_inventory_valuation_report_html" model="ir.actions.client">
<field name="name">Inventory Valuation Report</field>
<field name="tag">stock_inventory_valuation_report_backend</field>
<field name="context" eval="{'active_model': 'report.stock.inventory.valuation.report'}" />
<field
name="context"
eval="{'active_model': 'report.stock.inventory.valuation.report'}"
/>
</record>

<report string="Stock Inventory Valuation Report PDF"
id="action_stock_inventory_valuation_report_pdf"
model="report.stock.inventory.valuation.report"
name="stock_inventory_valuation_report.report_stock_inventory_valuation_report_pdf"
file="stock_inventory_valuation_report.report_stock_inventory_valuation_report_pdf"
report_type="qweb-pdf"
print_report_name="'Inventory Valuation Report - [%s]' % object.date"
paperformat="stock_inventory_valuation_report.paperformat_inventory_valuation_report"/>
<report
string="Stock Inventory Valuation Report PDF"
id="action_stock_inventory_valuation_report_pdf"
model="report.stock.inventory.valuation.report"
name="stock_inventory_valuation_report.report_stock_inventory_valuation_report_pdf"
file="stock_inventory_valuation_report.report_stock_inventory_valuation_report_pdf"
report_type="qweb-pdf"
print_report_name="'Inventory Valuation Report - [%s]' % object.date"
paperformat="stock_inventory_valuation_report.paperformat_inventory_valuation_report"
/>

<report string="Stock Inventory Valuation Report XLSX"
id="action_stock_inventory_valuation_report_xlsx"
model="report.stock.inventory.valuation.report"
name="s_i_v_r.report_stock_inventory_valuation_report_xlsx"
file="Inventory Valuation Report"
report_type="xlsx"
attachment_use="False"/>
<report
string="Stock Inventory Valuation Report XLSX"
id="action_stock_inventory_valuation_report_xlsx"
model="report.stock.inventory.valuation.report"
name="s_i_v_r.report_stock_inventory_valuation_report_xlsx"
file="Inventory Valuation Report"
report_type="xlsx"
attachment_use="False"
/>

</odoo>
Original file line number Diff line number Diff line change
Expand Up @@ -5,96 +5,105 @@


class StockInventoryValuationView(models.TransientModel):
_name = 'stock.inventory.valuation.view'
_description = 'Stock Inventory Valuation View'
_name = "stock.inventory.valuation.view"
_description = "Stock Inventory Valuation View"

name = fields.Char()
reference = fields.Char()
barcode = fields.Char()
qty_at_date = fields.Float()
uom_id = fields.Many2one(
comodel_name='uom.uom',
comodel_name="uom.uom",
)
currency_id = fields.Many2one(
comodel_name='res.currency',
comodel_name="res.currency",
)
cost_currency_id = fields.Many2one(
comodel_name='res.currency',
comodel_name="res.currency",
)
standard_price = fields.Float()
stock_value = fields.Float()
cost_method = fields.Char()


class StockInventoryValuationReport(models.TransientModel):
_name = 'report.stock.inventory.valuation.report'
_description = 'Stock Inventory Valuation Report'
_name = "report.stock.inventory.valuation.report"
_description = "Stock Inventory Valuation Report"

# Filters fields, used for data computation
company_id = fields.Many2one(
comodel_name='res.company',
comodel_name="res.company",
)
compute_at_date = fields.Integer()
date = fields.Datetime()

# Data fields, used to browse report data
results = fields.Many2many(
comodel_name='stock.inventory.valuation.view',
compute='_compute_results',
help='Use compute fields, so there is nothing store in database',
comodel_name="stock.inventory.valuation.view",
compute="_compute_results",
help="Use compute fields, so there is nothing store in database",
)

@api.multi
def _compute_results(self):
self.ensure_one()
if not self.compute_at_date:
self.date = fields.Datetime.now()
products = self.env['product.product'].\
with_context(dict(to_date=self.date, company_owned=True,
create=False, edit=False)).\
search([('type', '=', 'product'), ('qty_available', '!=', 0)])
ReportLine = self.env['stock.inventory.valuation.view']
products = (
self.env["product.product"]
.with_context(
dict(to_date=self.date, company_owned=True, create=False, edit=False)
)
.search([("type", "=", "product"), ("qty_available", "!=", 0)])
)
ReportLine = self.env["stock.inventory.valuation.view"]
for product in products:
standard_price = product.standard_price
if self.date:
standard_price = product.get_history_price(
self.env.user.company_id.id,
date=self.date)
self.env.user.company_id.id, date=self.date
)
line = {
'name': product.name,
'reference': product.default_code,
'barcode': product.barcode,
'qty_at_date': product.qty_at_date,
'uom_id': product.uom_id,
'currency_id': product.currency_id,
'cost_currency_id': product.cost_currency_id,
'standard_price': standard_price,
'stock_value': product.qty_at_date * standard_price,
'cost_method': product.cost_method,
"name": product.name,
"reference": product.default_code,
"barcode": product.barcode,
"qty_at_date": product.qty_at_date,
"uom_id": product.uom_id,
"currency_id": product.currency_id,
"cost_currency_id": product.cost_currency_id,
"standard_price": standard_price,
"stock_value": product.qty_at_date * standard_price,
"cost_method": product.cost_method,
}
if product.qty_at_date != 0:
self.results += ReportLine.new(line)

@api.multi
def print_report(self, report_type='qweb'):
def print_report(self, report_type="qweb"):
self.ensure_one()
action = report_type == 'xlsx' and self.env.ref(
'stock_inventory_valuation_report.'
'action_stock_inventory_valuation_report_xlsx') or \
self.env.ref('stock_inventory_valuation_report.'
'action_stock_inventory_valuation_report_pdf')
action = (
report_type == "xlsx"
and self.env.ref(
"stock_inventory_valuation_report."
"action_stock_inventory_valuation_report_xlsx"
)
or self.env.ref(
"stock_inventory_valuation_report."
"action_stock_inventory_valuation_report_pdf"
)
)
return action.report_action(self, config=False)

def _get_html(self):
result = {}
rcontext = {}
report = self.browse(self._context.get('active_id'))
report = self.browse(self._context.get("active_id"))
if report:
rcontext['o'] = report
result['html'] = self.env.ref(
'stock_inventory_valuation_report.'
'report_stock_inventory_valuation_report_html').render(
rcontext)
rcontext["o"] = report
result["html"] = self.env.ref(
"stock_inventory_valuation_report."
"report_stock_inventory_valuation_report_html"
).render(rcontext)
return result

@api.model
Expand Down
Loading

0 comments on commit e6c3bbe

Please sign in to comment.