采购协议
This commit is contained in:
@@ -1,4 +1,2 @@
|
||||
from . import sale_order_wizard
|
||||
from . import purchase_order_wizard
|
||||
from . import upload_file_upload
|
||||
from . import purchase_requisition_wizard
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
from odoo import models, fields, api, _
|
||||
import logging
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class PurchaseRequisition(models.Model):
|
||||
_inherit = 'purchase.requisition'
|
||||
|
||||
def action_confirm(self):
|
||||
purchase_order_id = self.env.context.get('purchase_order_id')
|
||||
purchase_order = self.env['purchase.order'].sudo().search([('id', '=', purchase_order_id)])
|
||||
if purchase_order.requisition_id.id == self.id:
|
||||
raise UserError(_('该采购订单已绑定%s协议') % purchase_order.name)
|
||||
if purchase_order.requisition_id:
|
||||
# 先解绑
|
||||
purchase_order.button_unlink_requisition()
|
||||
purchase_order.write({'requisition_id': self.id})
|
||||
self.purchase_ids += purchase_order
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record model="ir.ui.view" id="purchase_requisition_wizard_tree_view">
|
||||
<field name="name">purchase.requisition.wizard.tree.view</field>
|
||||
<field name="model">purchase.requisition</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree create="false" delete="false">
|
||||
<field name="name"/>
|
||||
<field name="partner_ref"/>
|
||||
<field name="contract_number"/>
|
||||
<field name="create_date"/>
|
||||
<button string="关联" type="object" name="action_confirm" class="btn-primary"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -1,60 +0,0 @@
|
||||
from odoo import models, fields, api, _
|
||||
|
||||
|
||||
class IrAttachmentUpload(models.TransientModel):
|
||||
_name = 'ir.attachment.upload'
|
||||
_description = '文件上传向导'
|
||||
|
||||
attachment = fields.Binary(string='选择文件', required=True)
|
||||
filename = fields.Char(string='文件名')
|
||||
res_model = fields.Char()
|
||||
res_id = fields.Integer()
|
||||
|
||||
def action_upload_file(self):
|
||||
self.ensure_one()
|
||||
# 获取当前用户的 partner_id
|
||||
current_partner = self.env.user.partner_id
|
||||
# 首先创建 ir.attachment
|
||||
attachment = self.env['ir.attachment'].create({
|
||||
'name': self.filename,
|
||||
'type': 'binary',
|
||||
'datas': self.attachment,
|
||||
'res_model': self.res_model,
|
||||
'res_id': self.res_id,
|
||||
})
|
||||
|
||||
# 获取默认的文档文件夹
|
||||
workspace = self.env['purchase.requisition'].update_documents_folder('待审')
|
||||
|
||||
# 创建 documents.document 记录
|
||||
document = self.env['documents.document'].create({
|
||||
'name': self.filename,
|
||||
'attachment_id': attachment.id,
|
||||
'folder_id': workspace.id,
|
||||
'res_model': self.res_model,
|
||||
'res_id': self.res_id,
|
||||
'partner_id': current_partner.id,
|
||||
})
|
||||
|
||||
# 更新采购订单的合同文档字段
|
||||
purchase_requisition = self.env['purchase.requisition'].browse(self.res_id)
|
||||
purchase_requisition.write({
|
||||
'contract_document_id': document.id,
|
||||
'is_upload_contract_file': True
|
||||
})
|
||||
|
||||
# 显示成功消息并关闭向导
|
||||
message = {
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'display_notification',
|
||||
'params': {
|
||||
'title': _('成功'),
|
||||
'message': _('文件上传成功'),
|
||||
'type': 'success',
|
||||
'sticky': False, # 自动消失
|
||||
'next': {
|
||||
'type': 'ir.actions.act_window_close'
|
||||
}
|
||||
}
|
||||
}
|
||||
return message
|
||||
@@ -1,21 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="view_upload_file_upload_form" model="ir.ui.view">
|
||||
<field name="name">ir.attachment.upload.form</field>
|
||||
<field name="model">ir.attachment.upload</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="上传文件">
|
||||
<group>
|
||||
<field name="attachment" widget="binary" filename="filename" options="{'accepted_file_extensions': '.pdf,.doc,.docx,.jpg,.jpeg,.png'}"/>
|
||||
<field name="filename" invisible="1"/>
|
||||
<field name="res_model" invisible="1"/>
|
||||
<field name="res_id" invisible="1"/>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="action_upload_file" string="确认上传" type="object" class="btn-primary"/>
|
||||
<button string="取消" class="btn-secondary" special="cancel"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user