@api.model def create(self, vals): if vals.get("code") in ('/', None, False): vals["code"] = self.env['ir.sequence'].next_by_code('roke.production.order.code') # app创建处理默认为客户(防止用户创建客户不勾选是否客户) if vals.__contains__("customer_id"): partner_id = self.env['roke.partner'].search([('id', '=', int(vals.get('customer_id')))], limit=1) if partner_id: partner_id.write({'customer': True}) return super(RokeProductionOrder, self).create(vals)
时间: 2024-04-05 08:32:48 浏览: 19
这是一个用于创建 RokeProductionOrder 记录的方法。在这个方法中,首先判断传入的参数中是否包含 code 字段,如果没有则使用 ir.sequence 生成一个唯一的 code 值。接着判断传入的参数中是否包含 customer_id 字段,如果有,则将对应的 partner 记录标记为客户。最后调用 super() 方法创建 RokeProductionOrder 记录并返回。这个方法的作用是自动生成 code 值并将对应的 partner 记录标记为客户,确保了数据的有效性和一致性。
相关问题
for i in vals:
This is a Python code snippet that loops through each element in the list "vals" and assigns it to the variable "i". The code that needs to be executed for each loop iteration should be indented below this line. For example:
```
vals = [1, 2, 3, 4, 5]
for i in vals:
print(i)
```
This code will print each element of the list "vals" on a new line.
def draw_stats(self, vals): self.ax1 = plt.subplot(1, 1, 1) self.ax1.plot(vals) self.ax1.set_xlim(self.xlim) locs = self.ax1.get_xticks() locs[0] = self.xlim[0] locs[-1] = self.xlim[1] self.ax1.set_xticks(locs) self.ax1.use_sticky_edges = False self.ax1.set_title(f'Connected Clients Ratio') plt.savefig('output.png', dpi=300) 中添加x轴y轴标签
可以使用以下代码在函数中添加x轴和y轴标签:
```python
def draw_stats(self, vals):
self.ax1 = plt.subplot(1, 1, 1)
self.ax1.plot(vals)
self.ax1.set_xlim(self.xlim)
locs = self.ax1.get_xticks()
locs[0] = self.xlim[0]
locs[-1] = self.xlim[1]
self.ax1.set_xticks(locs)
self.ax1.use_sticky_edges = False
self.ax1.set_title(f'Connected Clients Ratio')
self.ax1.set_xlabel('Time')
self.ax1.set_ylabel('Clients Ratio')
plt.savefig('output.png', dpi=300)
```
在上面的代码中,我们使用set_xlabel()和set_ylabel()函数分别添加x轴和y轴标签。这将在保存为PNG文件之前在图表中显示标签。