销售订单价格问题处理

This commit is contained in:
liaodanlong
2024-08-30 16:30:34 +08:00
parent c5bb9a32d0
commit 3624ef4755
3 changed files with 93 additions and 2 deletions

View File

@@ -37,7 +37,7 @@
<field name="date_planned_start" string="计划开始日期" optional="show"/> <field name="date_planned_start" string="计划开始日期" optional="show"/>
</xpath> </xpath>
<xpath expr="//field[@name='date_planned_start']" position="before"> <xpath expr="//field[@name='date_planned_start']" position="before">
<field name="reserved_duration" string="计划预留时间" optional="show"/> <field name="reserved_duration" string="计划预留时间" optional="hide"/>
</xpath> </xpath>
<xpath expr="//field[@name='date_planned_finished']" position="replace"> <xpath expr="//field[@name='date_planned_finished']" position="replace">
<field name="date_planned_finished" string="计划结束日期" optional="hide"/> <field name="date_planned_finished" string="计划结束日期" optional="hide"/>

View File

@@ -1,8 +1,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Part of SmartGo. See LICENSE file for full copyright and licensing details. # Part of SmartGo. See LICENSE file for full copyright and licensing details.
import logging import logging
import requests
from odoo import api, fields, models from odoo import api, fields, models
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError, UserError
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
@@ -144,3 +147,76 @@ class ResConfigSettings(models.TransientModel):
ir_config.set_param("ftp_user", self.ftp_user or "") ir_config.set_param("ftp_user", self.ftp_user or "")
ir_config.set_param("ftp_password", self.ftp_password or "") ir_config.set_param("ftp_password", self.ftp_password or "")
ir_config.set_param("enable_tool_presetter", self.enable_tool_presetter or False) ir_config.set_param("enable_tool_presetter", self.enable_tool_presetter or False)
def sync_sale_price(self):
self.get_page_all_records(self.sale_order_price_process)
def sale_order_price_process(self, datas):
if not datas:
return
try:
convert_sale_data = map(lambda data:
{'name': data.name, 'order_lines': {
'%s/%s/%s/%s%s/' % (
order_line.product_template_id.model_long, order_line.product_template_id.model_width, order_line.product_template_id.model_height,
order_line.product_template_id.model_volume,
order_line.product_template_id.model_machining_precision,
): order_line.price_unit for order_line in
data.order_line
}
},
datas)
config = self.env['res.config.settings'].get_values()
url = config['bfm_url_new'] + '/api/sync/order/price'
json_data = {
'params': {
'data': list(convert_sale_data),
},
}
response = requests.post(url, json=json_data, data=None)
response = response.json()
if not response.get('error'):
result = response.get('result')
for need_change_sale_data in result:
res_order_lines_map = need_change_sale_data.get('order_lines')
if not res_order_lines_map:
continue
need_change_sale_order = self.env['sale.order'].sudo().search([('name', '=', need_change_sale_data.get('name'))])
for need_change_sale_order_line in need_change_sale_order.order_line:
order_line_uniq='%s/%s/%s/%s%s/' % (
need_change_sale_order_line.product_template_id.model_long, need_change_sale_order_line.product_template_id.model_width,
need_change_sale_order_line.product_template_id.model_height,
need_change_sale_order_line.product_template_id.model_volume,
need_change_sale_order_line.product_template_id.model_machining_precision,
)
if not res_order_lines_map.get(order_line_uniq):
continue
need_change_sale_order_line.write({'price_unit': res_order_lines_map.get(order_line_uniq)})
else:
logging.error('同步销售订单价格失败 {}'.format(response.text))
raise UserError('同步销售订单价格失败')
except Exception as e:
raise UserError(e)
def get_page_all_records(self, func, page_size=100):
# 获取模型对象
model = self.env['sale.order'].sudo()
# 初始化分页参数
page_number = 1
while True:
# 计算偏移量
offset = (page_number - 1) * page_size
# 获取当前页的数据
records = model.search([], limit=page_size, offset=offset)
# 如果没有更多记录,退出循环
if not records:
break
# 将当前页的数据添加到结果列表
func(records)
# 增加页码
page_number += 1

View File

@@ -129,6 +129,21 @@
</div> </div>
</div> </div>
</div> </div>
<div>
<h2>销售订单价格同步</h2>
<div class="row mt16 o_settings_container">
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane"/>
<div class="o_setting_right_pane">
<div class="col-12 col-lg-6 o_setting_box">
<button type="object" class="oe_highlight" name="sync_sale_price" confirm="确认同步"
string="同步销售订单价格"
/>
</div>
</div>
</div>
</div>
</div>
</xpath> </xpath>
</field> </field>
</record> </record>