采购合同上传基础功能
This commit is contained in:
@@ -2,3 +2,4 @@
|
|||||||
|
|
||||||
from . import controllers
|
from . import controllers
|
||||||
from . import models
|
from . import models
|
||||||
|
from . import wizards
|
||||||
|
|||||||
@@ -20,13 +20,14 @@
|
|||||||
'version': '0.1',
|
'version': '0.1',
|
||||||
|
|
||||||
# any module necessary for this one to work correctly
|
# any module necessary for this one to work correctly
|
||||||
'depends': ['purchase', 'base_tier_validation'],
|
'depends': ['purchase', 'base_tier_validation', 'documents'],
|
||||||
|
|
||||||
# always loaded
|
# always loaded
|
||||||
'data': [
|
'data': [
|
||||||
# 'security/ir.model.access.csv',
|
'security/ir.model.access.csv',
|
||||||
|
'data/documents_data.xml',
|
||||||
|
'wizards/upload_file_wizard_view.xml',
|
||||||
'views/views.xml',
|
'views/views.xml',
|
||||||
'views/templates.xml',
|
|
||||||
],
|
],
|
||||||
# only loaded in demonstration mode
|
# only loaded in demonstration mode
|
||||||
'demo': [
|
'demo': [
|
||||||
|
|||||||
11
jikimo_purchase_tier_validation/data/documents_data.xml
Normal file
11
jikimo_purchase_tier_validation/data/documents_data.xml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
<data noupdate="1">
|
||||||
|
<!-- 创建采购合同文件夹 -->
|
||||||
|
<record id="documents_purchase_contracts_folder" model="documents.folder">
|
||||||
|
<field name="name">采购合同</field>
|
||||||
|
<field name="description">存放采购合同相关文件</field>
|
||||||
|
<field name="sequence">10</field>
|
||||||
|
</record>
|
||||||
|
</data>
|
||||||
|
</odoo>
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
from odoo import models, fields, api, _
|
from odoo import models, fields, api, _
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
|
|
||||||
|
|
||||||
class jikimo_purchase_tier_validation(models.Model):
|
class jikimo_purchase_tier_validation(models.Model):
|
||||||
_name = 'purchase.order'
|
_name = 'purchase.order'
|
||||||
_inherit = ['purchase.order', 'tier.validation']
|
_inherit = ['purchase.order', 'tier.validation']
|
||||||
@@ -17,3 +18,41 @@ class jikimo_purchase_tier_validation(models.Model):
|
|||||||
raise ValidationError(_('如下字段要求必须填写:%s') % '、'.join(missing_fields))
|
raise ValidationError(_('如下字段要求必须填写:%s') % '、'.join(missing_fields))
|
||||||
|
|
||||||
return super(jikimo_purchase_tier_validation, self).request_validation()
|
return super(jikimo_purchase_tier_validation, self).request_validation()
|
||||||
|
|
||||||
|
# 上传合同文件
|
||||||
|
def upload_contract_file(self):
|
||||||
|
print('upload_contract_file===========================')
|
||||||
|
# self.ensure_one()
|
||||||
|
# return {
|
||||||
|
# 'name': _('上传合同文件'),
|
||||||
|
# 'type': 'ir.actions.act_window',
|
||||||
|
# 'res_model': 'ir.attachment',
|
||||||
|
# 'view_mode': 'form',
|
||||||
|
# 'view_type': 'form',
|
||||||
|
# 'target': 'new',
|
||||||
|
# 'context': {
|
||||||
|
# 'default_res_model': self._name,
|
||||||
|
# 'default_res_id': self.id,
|
||||||
|
# 'default_type': 'binary',
|
||||||
|
# 'default_mimetype': 'application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,image/jpeg,image/png',
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
|
||||||
|
self.ensure_one()
|
||||||
|
action = {
|
||||||
|
'type': 'ir.actions.act_window',
|
||||||
|
'name': _('上传合同文件'),
|
||||||
|
'res_model': 'ir.attachment.wizard', # 我们需要创建一个新的向导模型
|
||||||
|
'view_mode': 'form',
|
||||||
|
'target': 'new',
|
||||||
|
'context': {
|
||||||
|
'default_res_model': self._name,
|
||||||
|
'default_res_id': self.id,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return action
|
||||||
|
|
||||||
|
# 删除合同文件
|
||||||
|
def delete_contract_file(self):
|
||||||
|
print('delete_contract_file============================')
|
||||||
|
pass
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||||
access_jikimo_purchase_tier_validation_jikimo_purchase_tier_validation,jikimo_purchase_tier_validation.jikimo_purchase_tier_validation,model_jikimo_purchase_tier_validation_jikimo_purchase_tier_validation,base.group_user,1,1,1,1
|
access_ir_attachment_wizard,ir.attachment.wizard,model_ir_attachment_wizard,base.group_user,1,1,1,1
|
||||||
|
@@ -1,19 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<odoo>
|
<odoo>
|
||||||
<data>
|
<data>
|
||||||
<!-- explicit list view definition -->
|
<record model="ir.ui.view" id="tier_validation_view_purchase_order_form_inherit">
|
||||||
<!--
|
<field name="name">tier_validation_view_purchase_order_form_inherit</field>
|
||||||
<record model="ir.ui.view" id="jikimo_purchase_tier_validation.list">
|
<field name="model">purchase.order</field>
|
||||||
<field name="name">jikimo_purchase_tier_validation list</field>
|
<field name="inherit_id" ref="purchase.purchase_order_form"/>
|
||||||
<field name="model">jikimo_purchase_tier_validation.jikimo_purchase_tier_validation</field>
|
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree>
|
<xpath expr="//header" position="inside">
|
||||||
<field name="name"/>
|
<button name="upload_contract_file" string="上传合同" type="object" class="oe_highlight"/>
|
||||||
<field name="value"/>
|
<button name="delete_contract_file" string="删除合同" type="object" class="oe_highlight"/>
|
||||||
<field name="value2"/>
|
</xpath>
|
||||||
</tree>
|
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
-->
|
|
||||||
|
|
||||||
<!-- actions opening views on models -->
|
<!-- actions opening views on models -->
|
||||||
<!--
|
<!--
|
||||||
|
|||||||
1
jikimo_purchase_tier_validation/wizards/__init__.py
Normal file
1
jikimo_purchase_tier_validation/wizards/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import upload_file_wizard
|
||||||
103
jikimo_purchase_tier_validation/wizards/upload_file_wizard.py
Normal file
103
jikimo_purchase_tier_validation/wizards/upload_file_wizard.py
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
from odoo import models, fields, api, _
|
||||||
|
|
||||||
|
|
||||||
|
class IrAttachmentWizard(models.TransientModel):
|
||||||
|
_name = 'ir.attachment.wizard'
|
||||||
|
_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()
|
||||||
|
# # 首先创建 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['documents.folder'].search([('name', '=', '采购合同')], limit=1)
|
||||||
|
#
|
||||||
|
# # 创建 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,
|
||||||
|
# })
|
||||||
|
#
|
||||||
|
# return {
|
||||||
|
# 'type': 'ir.actions.client',
|
||||||
|
# 'tag': 'display_notification',
|
||||||
|
# 'params': {
|
||||||
|
# 'title': _('成功'),
|
||||||
|
# 'message': _('文件上传成功'),
|
||||||
|
# 'type': 'success',
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
|
||||||
|
def action_upload_file(self):
|
||||||
|
self.ensure_one()
|
||||||
|
# 首先创建 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['documents.folder'].search([('name', '=', '采购合同')], limit=1)
|
||||||
|
|
||||||
|
# 创建 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,
|
||||||
|
})
|
||||||
|
|
||||||
|
# 显示成功消息并关闭向导
|
||||||
|
message = {
|
||||||
|
'type': 'ir.actions.client',
|
||||||
|
'tag': 'display_notification',
|
||||||
|
'params': {
|
||||||
|
'title': _('成功'),
|
||||||
|
'message': _('文件上传成功'),
|
||||||
|
'type': 'success',
|
||||||
|
'sticky': False, # 自动消失
|
||||||
|
'next': {
|
||||||
|
'type': 'ir.actions.act_window_close'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return message
|
||||||
|
|
||||||
|
|
||||||
|
# def action_upload_file(self):
|
||||||
|
# self.ensure_one()
|
||||||
|
# attachment = self.env['ir.attachment'].create({
|
||||||
|
# 'name': self.filename,
|
||||||
|
# 'type': 'binary',
|
||||||
|
# 'datas': self.attachment,
|
||||||
|
# 'res_model': self.res_model,
|
||||||
|
# 'res_id': self.res_id,
|
||||||
|
# })
|
||||||
|
# return {
|
||||||
|
# 'type': 'ir.actions.client',
|
||||||
|
# 'tag': 'display_notification',
|
||||||
|
# 'params': {
|
||||||
|
# 'title': _('成功'),
|
||||||
|
# 'message': _('文件上传成功'),
|
||||||
|
# 'type': 'success',
|
||||||
|
# }
|
||||||
|
# }
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
<record id="view_upload_file_wizard_form" model="ir.ui.view">
|
||||||
|
<field name="name">ir.attachment.wizard.form</field>
|
||||||
|
<field name="model">ir.attachment.wizard</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