Commit dd28d5f9 by 夏超

[fix] 收入支出修改

parent cc119079
......@@ -27,36 +27,31 @@ class ProductIncomeExpenseIframe(http.Controller):
def product_income_expense_create(self):
_self = http.request
data_list = _self.jsonrequest.get("data_list", [])
return_data = []
for v in data_list:
data = {
"business_date": v.get("business_date", False),
"abstract": v.get("abstract", False),
"income": v.get("income", False),
"expenditure": v.get("expenditure", False),
"balance": v.get("balance", False)
"expenditure": v.get("expenditure", False)
}
result = _self.env(user=v.get("user_id"))["roke.product.income.expense"].create(data)
return_data.append({
"id": result.id,
"business_date": result.business_date and result.business_date.strftime('%Y-%m-%d'),
"abstract": result.abstract or "",
"income": result.income or 0,
"expenditure": result.expenditure or 0,
"balance": result.balance or 0,
"user_name": result.create_uid.name or "",
"create_date": (result.create_date + datetime.timedelta(hours=8)).strftime('%Y-%m-%d %H:%M'),
})
return {"code": 0, "message": "创建成功!", "data": return_data}
_self.env(user=v.get("user_id"))["roke.product.income.expense"].create(data)
return {"code": 0, "message": "创建成功!"}
@http.route("/roke/product/product_income_expense/get", type="json", auth='none', cors='*', csrf=False)
def product_income_expense_get_list(self):
_self = http.request
limit = _self.jsonrequest.get("limit", 20)
page = _self.jsonrequest.get("page", 1)
data_list = _self.env["roke.product.income.expense"].sudo().search([], limit=limit, offset=(page - 1) * limit,
start_date = _self.jsonrequest.get("start_date", "")
end_date = _self.jsonrequest.get("end_date", "")
domain = []
if start_date and end_date:
domain.append(("business_date", ">=", start_date))
domain.append(("business_date", "<=", end_date))
data_list = _self.env["roke.product.income.expense"].sudo().search(domain, limit=limit,
offset=(page - 1) * limit,
order="create_date desc")
count = _self.env["roke.product.income.expense"].sudo().search_count([])
count = _self.env["roke.product.income.expense"].sudo().search_count(domain)
data = []
for v in data_list:
data.append({
......
......@@ -13,4 +13,17 @@ class ProductIncomeExpense(models.Model):
abstract = fields.Text(string="摘要")
income = fields.Float(string="收入")
expenditure = fields.Float(string="支出")
balance = fields.Float(string="结余")
balance = fields.Float(string="结余", compute="_compute_balance")
@api.depends("income", "expenditure")
def _compute_balance(self):
data = self.search([("id", "in", self.ids)], order="create_date asc")
for v in data:
last_data = self.search([
("create_date", "<", v.create_date),
("id", "!=", v.id)
], limit=1, order="create_date desc")
if not last_data:
v.balance = 0 + v.income - v.expenditure
else:
v.balance = last_data.balance + v.income - v.expenditure
......@@ -17,56 +17,92 @@
</head>
<body>
<div id="app">
<div style="text-align: right; margin-bottom: 10px;">
<div id="app" v-loading="loading" element-loading-text="加载中...">
<div style="margin-bottom: 20px;">
<el-table :data="createList" border :row-style="{height: '0'}"
style="width: 100%;border: 1px solid black;border-color: black" :cell-style="tableCellStyle"
:header-cell-style="tableHeaderCellStyle">
<el-table-column label="业务日期" align="center" width="166">
<template slot-scope="scope">
<el-date-picker v-model="scope.row.business_date" type="date" format="yyyy-MM-dd"
value-format="yyyy-MM-dd" placeholder="选择日期">
</el-date-picker>
</template>
</el-table-column>
<el-table-column label="摘要" align="center">
<template slot-scope="scope">
<el-input v-model="scope.row.abstract" placeholder="请输入"></el-input>
</template>
</el-table-column>
<el-table-column label="收入" align="center" width="120">
<template slot-scope="scope">
<el-input v-model="scope.row.income" type="number" placeholder="请输入"></el-input>
</template>
</el-table-column>
<el-table-column label="支出" align="center" width="120">
<template slot-scope="scope">
<el-input v-model="scope.row.expenditure" type="number" placeholder="请输入"></el-input>
</template>
</el-table-column>
<el-table-column label="创建人" align="center" width="110">
<template slot-scope="scope">
<div>
[[ scope.row.user_name ]]
</div>
</template>
</el-table-column>
<el-table-column label="操作" align="center" width="95">
<template slot-scope="scope">
<el-button type="primary" @click="saveListData">保存</el-button>
<el-button type="primary" icon="el-icon-plus" @click="addData">添加</el-button>
</template>
</el-table-column>
</el-table>
</div>
<div style="text-align: right; margin-bottom: 5px;">
<el-date-picker v-model="datePickerValue" type="daterange" range-separator="至" start-placeholder="开始日期"
end-placeholder="结束日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
@change="datePickerChange">
</el-date-picker>
</div>
<el-table :data="dataList" border height="578" v-loading="loading" :row-style="{height: '0'}"
<el-table :data="dataList" border height="500" :row-style="{height: '0'}"
style="width: 100%;border: 1px solid black;border-color: black" :cell-style="tableCellStyle"
:header-cell-style="tableHeaderCellStyle">
<el-table-column label="业务日期" align="center" width="166">
<template slot-scope="scope">
<div v-if="scope.row.id">
<div>
[[ scope.row.business_date ]]
</div>
<el-date-picker v-else v-model="scope.row.business_date" type="date" format="yyyy-MM-dd"
value-format="yyyy-MM-dd" placeholder="选择日期">
</el-date-picker>
</template>
</el-table-column>
<el-table-column label="摘要" align="center" width="600">
<el-table-column label="摘要" align="center">
<template slot-scope="scope">
<div v-if="scope.row.id">
<div style="text-align: left;">
[[ scope.row.abstract ]]
</div>
<el-input v-else style="width: 570px;" v-model="scope.row.abstract" placeholder="请输入摘要"></el-input>
</template>
</el-table-column>
<el-table-column label="收入" align="center">
<el-table-column label="收入" align="center" width="120">
<template slot-scope="scope">
<div v-if="scope.row.id">
<div style="text-align: right;">
[[ scope.row.income ]]
</div>
<el-input v-else v-model="scope.row.income" type="number" placeholder="请输入收入"
@input="calculationFormula(scope.row)"></el-input>
</template>
</el-table-column>
<el-table-column label="支出" align="center">
<el-table-column label="支出" align="center" width="120">
<template slot-scope="scope">
<div v-if="scope.row.id">
<div style="text-align: right;">
[[ scope.row.expenditure ]]
</div>
<el-input v-else v-model="scope.row.expenditure" type="number" placeholder="请输入支出"
@input="calculationFormula(scope.row)"></el-input>
</template>
</el-table-column>
<el-table-column label="结余" align="center" width="110">
<el-table-column label="结余" align="center" width="120">
<template slot-scope="scope">
<div>
[[ scope.row.balance ]]
</div>
<!-- <el-input v-else v-model="scope.row.balance" placeholder="请输入结余"></el-input> -->
</template>
</el-table-column>
<el-table-column label="创建人" align="center" width="110">
......@@ -76,7 +112,7 @@
</div>
</template>
</el-table-column>
<el-table-column label="创建时间" align="center">
<el-table-column label="创建时间" align="center" width="160">
<template slot-scope="scope">
<div>
[[ scope.row.create_date ]]
......@@ -91,7 +127,7 @@
</el-table>
<div style="margin-top: 10px; text-align: center;">
<el-pagination :current-page="currentPageNo" :total="paginationTotal" @current-change="handleCurrentChangee"
:page-size="20" layout="prev, pager, next,total">
:page-size="10" layout="prev, pager, next,total">
</el-pagination>
</div>
</div>
......@@ -104,63 +140,57 @@
data() {
return {
TableHeight: 0,
input: '',
dateValue: '',
currentPageNo: 1,
paginationTotal: 100,
paginationTotal: 10,
loading: false,
dataList: [],
user_name: '',
user_id: null
user_id: null,
createList: [
{
business_date: '',
abstract: '',
income: '',
expenditure: '',
user_name: '',
user_id: null,
}
],
datePickerValue: ['', '']
};
},
created() {
this.user_name = this.getUrlSearch('user_name') //截取url后面的参数
this.user_id = this.getUrlSearch('user_id')
this.createList[0].user_name = this.user_name
this.createList[0].business_date = moment().format("YYYY-MM-DD")
this.createList[0].user_id = this.user_id
this.TableHeight = window.innerHeight;
// axios.request({
// url: "/roke/mes/client_login",
// method: "post",
// headers: {
// "Content-Type": "application/json",
// },
// data: {
// "login": "admin",
// "password": "admin"
// },
// }).then((res) => {
// });
this.getDataList()
},
methods: {
// 收入-支出 = 结余
calculationFormula(e) {
e.balance = e.income - e.expenditure
},
// table样式
tableCellStyle() {
return "border-color:black;"
},
// 修改 table header cell的背景色
tableHeaderCellStyle() {
return 'background: #eef1f6;border-color: black;color:black'
// 列表 时间过滤
datePickerChange(e) {
console.log(e);
if (!e) {
this.datePickerValue = ['', '']
}
this.getDataList()
},
// 分页请求数据
handleCurrentChangee(val, condition) {
handleCurrentChangee(val) {
this.currentPageNo = val;
this.getDataList(condition)
this.getDataList()
},
// 获取列表数据
getDataList(condition) {
console.log(condition);
if(!condition){
// 获取列表数据
getDataList() {
this.loading = true;
}
let parameter = {
limit: 20, //每页数量 非必填
page: this.currentPageNo, //当前页码 非必填
limit: 10, //每页数量 非必填
page: this.currentPageNo, //当前页码
start_date: this.datePickerValue[0],
end_date: this.datePickerValue[1]
}
axios.request({
url: "/roke/product/product_income_expense/get",
......@@ -173,19 +203,6 @@
if (res.data.result.code === 0) {
this.paginationTotal = res.data.result.count
this.dataList = res.data.result.data
if (condition == 'addData') {
const now = moment();
this.dataList.unshift({
business_date: now.format("YYYY-MM-DD"), //业务日期
abstract: '', //摘要
income: '', //收入
expenditure: '',//支出
balance: 0,//结余
user_name: this.user_name, //创建人
user_id:this.user_id,
create_date: ''//创建时间
})
}
} else {
this.$message({
type: "error",
......@@ -195,10 +212,6 @@
this.loading = false;
});
},
// 加载更多数据的函数
loadMoreData() {
// 添加更多数据到 tableData 中
},
// 删除
deleteItem(item, index) {
if (item.row.id) {
......@@ -218,7 +231,7 @@
type: "success",
message: res.data.result.message || "删除成功",
});
this.dataList.splice(item.$index, 1)
this.getDataList()
} else {
this.$message({
type: "error",
......@@ -232,33 +245,9 @@
}
},
// 添加
addData() {
if (this.currentPageNo == 1) {
const now = moment();
this.dataList.unshift({
business_date: now.format("YYYY-MM-DD"), //业务日期
abstract: '', //摘要
income: '', //收入
expenditure: '',//支出
balance: 0,//结余
user_name: this.user_name, //创建人
user_id:this.user_id,
create_date: ''//创建时间
})
} else {
this.handleCurrentChangee(1, 'addData')
}
},
// 保存
saveListData() {
let parameterList = []
this.dataList.forEach(item => {
if (!item.id) {
parameterList.push(item)
}
});
if (parameterList.length != 0) {
if (this.createList[0].income != '' || this.createList[0].expenditure != '') {
this.loading = true;
axios.request({
url: "/roke/product/product_income_expense/create",
......@@ -267,7 +256,7 @@
"Content-Type": "application/json",
},
data: {
data_list: parameterList
data_list: this.createList
}
}).then((res) => {
if (res.data.result.code === 0) {
......@@ -276,6 +265,16 @@
message: res.data.result.message || "创建成功",
});
this.currentPageNo = 1
this.createList = [
{
business_date: moment().format("YYYY-MM-DD"),
abstract: '',
income: '',
expenditure: '',
user_name: this.user_name,
user_id: this.user_id
}
]
this.getDataList()
} else {
this.$message({
......@@ -288,10 +287,18 @@
} else {
this.$message({
type: "warning",
message: "请添加新记录后保存",
message: "请填写收入或支出后保存",
});
}
},
// table样式
tableCellStyle() {
return "border-color:black;"
},
// 修改 table header cell的背景色
tableHeaderCellStyle() {
return 'background: #eef1f6;border-color: black;color:black'
},
// 通过网址跳转过来的页面,截取后面的参数
getUrlSearch(name) {
// 未传参,返回空
......@@ -321,17 +328,13 @@
}
body {
padding: 15px 50px 30px 50px;
padding: 15px 35px 30px 35px;
}
.el-table .el-table__cell {
padding: 4px 0;
padding: 3px 0;
}
/* .el-input {
width: 120px;
} */
.el-date-editor.el-input {
width: 140px;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment