Files
test/sf_purchase_arrival_inform/wizard/purchase_confirm_wizard.py
2025-07-17 15:20:34 +08:00

64 lines
2.4 KiB
Python

from odoo import models, fields, api, _
class PurchaseConfirmWizard(models.TransientModel):
_name = 'purchase.confirm.wizard'
_description = '采购订单确认向导'
purchase_order_id = fields.Many2one('purchase.order', string='采购订单', required=True)
line_ids = fields.One2many('purchase.confirm.wizard.line', 'wizard_id', string='产品明细')
@api.model_create_multi
def create(self, vals_list):
"""创建向导时自动生成产品明细"""
records = super().create(vals_list)
for record in records:
if record.purchase_order_id:
# 自动创建产品明细行
line_data = []
for line in record.purchase_order_id.order_line:
line_data.append({
'wizard_id': record.id,
'product_id': line.product_id.id,
'product_name': line.product_id.name,
'product_qty': line.product_qty,
'product_uom': line.product_uom.name,
'uom_rounding': line.product_uom.rounding,
})
if line_data:
self.env['purchase.confirm.wizard.line'].create(line_data)
return records
def action_confirm(self):
"""确认采购订单"""
if self.purchase_order_id:
# 调用原始的确认方法
self.purchase_order_id._execute_original_confirm()
# 返回关闭向导并刷新采购订单页面
return {
'type': 'ir.actions.act_window_close',
'infos': {
'title': _('成功'),
'message': _('采购订单已确认成功!'),
}
}
def action_cancel(self):
"""取消操作"""
return {'type': 'ir.actions.act_window_close'}
class PurchaseConfirmWizardLine(models.TransientModel):
_name = 'purchase.confirm.wizard.line'
_description = '采购订单确认向导明细'
wizard_id = fields.Many2one('purchase.confirm.wizard', string='向导', ondelete='cascade')
product_id = fields.Many2one('product.product', string='产品')
product_name = fields.Char(string='产品名称')
product_qty = fields.Float(string='数量')
product_uom = fields.Char(string='单位')
uom_rounding = fields.Float(string='舍入精度')