diff --git a/yuthon_report/__init__.py b/yuthon_report/__init__.py index 8b1378917..0650744f6 100644 --- a/yuthon_report/__init__.py +++ b/yuthon_report/__init__.py @@ -1 +1 @@ - +from . import models diff --git a/yuthon_report/__manifest__.py b/yuthon_report/__manifest__.py index de752798a..c852ab09f 100644 --- a/yuthon_report/__manifest__.py +++ b/yuthon_report/__manifest__.py @@ -8,7 +8,8 @@ 'license': 'LGPL-3', 'depends': ['base', 'web'], 'data': [ - + 'views/menu.xml', + 'views/yuthon_report_res_partner.xml' ], 'installable': True, 'application': True, @@ -16,10 +17,12 @@ 'web.assets_backend': [ # 样式 'yuthon_report/static/src/lib/ag-grid-c/styles/ag-grid.css', - 'yuthon_report/static/src/lib/ag-grid-c/styles/ag-theme-alpine.css', + # 'yuthon_report/static/src/lib/ag-grid-c/styles/ag-theme-alpine.css', + # 'yuthon_report/static/src/lib/ag-grid-c/styles/ag-theme-balham.min.css', + 'yuthon_report/static/src/lib/ag-grid-c/styles/ag-theme-quartz.min.css', # 先引入 community - 'yuthon_report/static/src/lib/ag-grid-c/dist/ag-grid-community.noStyle.js', + 'yuthon_report/static/src/lib/ag-grid-c/dist/ag-grid-community.js', # 再引入 enterprise 'yuthon_report/static/src/lib/ag-grid-e/dist/ag-grid-enterprise.js', diff --git a/yuthon_report/models/__init__.py b/yuthon_report/models/__init__.py new file mode 100644 index 000000000..26fd9feec --- /dev/null +++ b/yuthon_report/models/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import res_partner \ No newline at end of file diff --git a/yuthon_report/models/res_partner.py b/yuthon_report/models/res_partner.py new file mode 100644 index 000000000..36e703fa7 --- /dev/null +++ b/yuthon_report/models/res_partner.py @@ -0,0 +1,16 @@ +from odoo import fields, models, api + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + @api.model + def get_report_data(self, params): + domain = [] + if params.get("keyword"): + domain.append(("name", "ilike", params["keyword"])) + partners = self.search(domain, limit=100) + return [ + {"customer": p.name, "amount": p.credit} + for p in partners + ] diff --git a/yuthon_report/static/description/icon.png b/yuthon_report/static/description/icon.png new file mode 100644 index 000000000..89f76073e Binary files /dev/null and b/yuthon_report/static/description/icon.png differ diff --git a/yuthon_report/static/src/components/yuthon_report/yuthon_report.js b/yuthon_report/static/src/components/yuthon_report/yuthon_report.js index 13c10175d..4b69e2acd 100644 --- a/yuthon_report/static/src/components/yuthon_report/yuthon_report.js +++ b/yuthon_report/static/src/components/yuthon_report/yuthon_report.js @@ -3,12 +3,17 @@ import { registry } from "@web/core/registry"; import { Component, onMounted, useRef, useState } from "@odoo/owl"; +import { useBus, useService } from "@web/core/utils/hooks"; +import { standardActionServiceProps } from "@web/webclient/actions/action_service"; +import { DateTimeInput } from "@web/core/datetime/datetime_input"; class YouthonReport extends Component { setup() { this.gridRef = useRef("grid"); - this.dateRangeRef = useRef("date_range_picker"); - this.keywordRef = useRef("keyword_input"); + console.log('131231') + console.log(this.props.action.context.report_config) + + this.serviceOrm = useService("orm") this.state = useState({ startDate: null, @@ -16,17 +21,19 @@ class YouthonReport extends Component { keyword: "", }); - this.config = this.props.config || {}; + this.config = this.props.action.context.report_config || {}; onMounted(async () => { // 加载 ag-grid //await loadJS("https://cdn.jsdelivr.net/npm/ag-grid-community/dist/ag-grid-community.min.js"); this.gridOptions = { + theme:agGrid.themeMaterial, columnDefs: this.config.columns || [], rowData: [], + sideBar: true, defaultColDef: { resizable: true, sortable: true, filter: true }, }; - this.grid = new agGrid.Grid(this.gridRef.el, this.gridOptions); + this.grid = new agGrid.createGrid(this.gridRef.el, this.gridOptions); }); } @@ -37,15 +44,33 @@ class YouthonReport extends Component { date_end: this.state.endDate, keyword: this.state.keyword, }; - - const result = await this.env.services.orm.call( + const result = await this.serviceOrm.call( this.config.model, this.config.method, [params] ); - this.gridOptions.api.setRowData(result); + console.log(result) + this.grid.setGridOption('rowData',result); } + + onExportExcel() { + this.grid.exportDataAsExcel({ + fileName: 'my-data.xlsx', + sheetName: 'Sheet1' + }); } + async onChangeStartDate(date){ + this.state.startDate = date; + } + async onChangeEndDate(date){ + this.state.endDate = date; + } +} +YouthonReport.props = {...standardActionServiceProps }; YouthonReport.template = "youthon_report.YouthonReport"; +YouthonReport.components = { + DateTimeInput +}; + registry.category("actions").add("youthon_report_client", YouthonReport); diff --git a/yuthon_report/static/src/components/yuthon_report/yuthon_report.xml b/yuthon_report/static/src/components/yuthon_report/yuthon_report.xml index ad6fb1e32..de968aea9 100644 --- a/yuthon_report/static/src/components/yuthon_report/yuthon_report.xml +++ b/yuthon_report/static/src/components/yuthon_report/yuthon_report.xml @@ -1,30 +1,55 @@ -
- -
-
- -
-
-
- -
-
-
- -
-
+
+
+
+ 销售报表 +
+
+ +
+
+ + + + +
+
+ +
+ +
+
+
- -
+ + + +
+
+
+
+ + +
-
+
+ diff --git a/yuthon_report/views/menu.xml b/yuthon_report/views/menu.xml new file mode 100644 index 000000000..140196efd --- /dev/null +++ b/yuthon_report/views/menu.xml @@ -0,0 +1,13 @@ + + + + + + + + \ No newline at end of file diff --git a/yuthon_report/views/yuthon_report_res_partner.xml b/yuthon_report/views/yuthon_report_res_partner.xml new file mode 100644 index 000000000..73740df04 --- /dev/null +++ b/yuthon_report/views/yuthon_report_res_partner.xml @@ -0,0 +1,36 @@ + + + + + + Youthon 报表 + youthon_report_client + + { + "sideBar":true, + "report_config": { + "model": "res.partner", + "method": "get_report_data", + "search_fields": [ + {"name": "date_start", "type": "date", "label": "开始日期"}, + {"name": "date_end", "type": "date", "label": "结束日期"}, + {"name": "keyword", "type": "char", "label": "关键字"} + ], + "columns": [ + {"headerName": "客户", "field": "customer", "flex": 1}, + {"headerName": "销售额", "field": "amount", "flex": 1} + ] + } + } + + + + + + + \ No newline at end of file