来一段odoo库存计价的代码
时间: 2023-03-07 17:50:58 浏览: 139
我们可以使用下列代码来计算odoo库存的计价:from odoo import models, fields, apiclass StockPricing(models.Model):
_name = 'stock.pricing'
product_id = fields.Many2one('product.product', string='Product', required=True)
quantity = fields.Float(string='Quantity', digits=(16,2))
total_amount = fields.Float(string='Total Amount', digits=(16,2))
@api.depends('product_id', 'quantity')
def _compute_total_amount(self):
for record in self:
record.total_amount = record.product_id.list_price * record.quantity
相关问题
来一段odoo审批流的核心代码
请参考以下代码:from odoo import api, modelsclass Workflow(models.Model):
_name = 'workflow' @api.multi
def create_workflow(self):
self.ensure_one()
workflow_obj = self.env['workflow.workflow']
workflow_data = {
'name': self.name,
'description': self.description,
'state': self.state,
}
workflow = workflow_obj.create(workflow_data)
workflow_step_obj = self.env['workflow.step']
for step in self.steps:
workflow_step_data = {
'name': step.name,
'description': step.description,
'workflow_id': workflow.id,
}
workflow_step_obj.create(workflow_step_data)
return workflow
odoo excel导出代码
在Odoo中,可以使用Python代码来实现Excel导出功能。下面是一个简单的示例代码,用于将Odoo模型中的数据导出为Excel文件:
```python
import xlwt
def export_to_excel(records):
# 创建一个新的Excel工作簿
workbook = xlwt.Workbook()
# 创建一个工作表
worksheet = workbook.add_sheet('Sheet1')
# 写入表头
headers = ['字段1', '字段2', '字段3']
for col_num, header in enumerate(headers):
worksheet.write(0, col_num, header)
# 写入数据
for row_num, record in enumerate(records, start=1):
worksheet.write(row_num, 0, record.field1)
worksheet.write(row_num, 1, record.field2)
worksheet.write(row_num, 2, record.field3)
# 保存Excel文件
workbook.save('exported_data.xls')
# 调用导出函数
records = env['your.model'].search([])
export_to_excel(records)
```
请注意,上述代码中的`your.model`需要替换为您要导出数据的实际模型名称,`字段1`、`字段2`和`字段3`需要替换为您要导出的实际字段名称。
阅读全文