mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-23 18:04:34 +00:00
Change CI to GitHub actions
Use copier template from oca/oca-addons-repo-template Apply linting
This commit is contained in:
@@ -6,10 +6,9 @@
|
||||
"version": "12.0.1.0.0",
|
||||
"category": "Tests",
|
||||
"author": "Camptocamp,Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/camptocamp/odoo-cloud-platform",
|
||||
"license": "AGPL-3",
|
||||
"depends": [
|
||||
"base_fileurl_field"
|
||||
],
|
||||
"depends": ["base_fileurl_field"],
|
||||
"data": [
|
||||
"views/res_partner.xml",
|
||||
"views/res_users.xml",
|
||||
|
||||
@@ -1 +1 @@
|
||||
This is a simple text file.
|
||||
This is a simple text file.
|
||||
|
||||
@@ -1,44 +1,46 @@
|
||||
# Copyright 2019 Camptocamp SA
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
|
||||
from odoo import models, fields, api, _
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class ResPartner(models.Model):
|
||||
|
||||
_inherit = 'res.partner'
|
||||
_inherit = "res.partner"
|
||||
|
||||
name = fields.Char()
|
||||
url_file = fields.FileURL(
|
||||
storage_location='s3',
|
||||
filename='url_file_fname',
|
||||
storage_path='partner'
|
||||
storage_location="s3", filename="url_file_fname", storage_path="partner"
|
||||
)
|
||||
url_file_fname = fields.Char()
|
||||
|
||||
url_image = fields.FileURL(
|
||||
storage_location='s3',
|
||||
filename='url_image_fname',
|
||||
storage_path='partner_image',
|
||||
storage_location="s3",
|
||||
filename="url_image_fname",
|
||||
storage_path="partner_image",
|
||||
)
|
||||
url_image_fname = fields.Char()
|
||||
|
||||
@api.constrains('url_file', 'url_file_fname')
|
||||
@api.constrains("url_file", "url_file_fname")
|
||||
def _check_url_file_fname(self):
|
||||
rec = self.search([('url_file_fname', '=', self.url_file_fname)])
|
||||
rec = self.search([("url_file_fname", "=", self.url_file_fname)])
|
||||
if len(rec) > 1:
|
||||
raise ValidationError(_(
|
||||
"This file name is already used on an existing record. "
|
||||
"Please use another file name or delete the url_file on :\n"
|
||||
"Model: %s Id: %s" % (self._name, rec.id)
|
||||
))
|
||||
raise ValidationError(
|
||||
_(
|
||||
"This file name is already used on an existing record. "
|
||||
"Please use another file name or delete the url_file on :\n"
|
||||
"Model: %s Id: %s" % (self._name, rec.id)
|
||||
)
|
||||
)
|
||||
|
||||
@api.constrains('url_image', 'url_image_fname')
|
||||
@api.constrains("url_image", "url_image_fname")
|
||||
def _check_url_image_fname(self):
|
||||
rec = self.search([('url_image_fname', '=', self.url_image_fname)])
|
||||
rec = self.search([("url_image_fname", "=", self.url_image_fname)])
|
||||
if len(rec) > 1:
|
||||
raise ValidationError(_(
|
||||
"This file name is already used on an existing record. "
|
||||
"Please use another file name or delete the url_image on :\n"
|
||||
"Model: %s Id: %s" % (self._name, rec.id)
|
||||
))
|
||||
raise ValidationError(
|
||||
_(
|
||||
"This file name is already used on an existing record. "
|
||||
"Please use another file name or delete the url_image on :\n"
|
||||
"Model: %s Id: %s" % (self._name, rec.id)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
# Copyright 2019 Camptocamp SA
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
|
||||
from odoo import models, fields
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResUsers(models.Model):
|
||||
|
||||
_inherit = 'res.users'
|
||||
_inherit = "res.users"
|
||||
|
||||
partner_url_file = fields.FileURL(related='partner_id.url_file')
|
||||
partner_url_file_fname = fields.Char(related='partner_id.url_file_fname')
|
||||
partner_url_file = fields.FileURL(related="partner_id.url_file")
|
||||
partner_url_file_fname = fields.Char(related="partner_id.url_file_fname")
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import logging
|
||||
|
||||
from odoo import models, api
|
||||
from odoo import api, models
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -14,23 +14,23 @@ class IrAttachment(models.Model):
|
||||
_inherit = "ir.attachment"
|
||||
|
||||
def _get_stores(self):
|
||||
l = ['s3']
|
||||
l = ["s3"]
|
||||
l += super(IrAttachment, self)._get_stores()
|
||||
return l
|
||||
|
||||
@api.model
|
||||
def _store_file_read(self, fname, bin_size=False):
|
||||
if fname.startswith('s3://'):
|
||||
if fname.startswith("s3://"):
|
||||
return FAKE_S3_BUCKET.get(fname)
|
||||
else:
|
||||
return super(IrAttachment, self)._store_file_read(fname, bin_size)
|
||||
|
||||
@api.model
|
||||
def _store_file_write(self, key, bin_data):
|
||||
location = self.env.context.get('storage_location') or self._storage()
|
||||
if location == 's3':
|
||||
location = self.env.context.get("storage_location") or self._storage()
|
||||
if location == "s3":
|
||||
FAKE_S3_BUCKET[key] = bin_data
|
||||
filename = 's3://fake_bucket/%s' % key
|
||||
filename = "s3://fake_bucket/%s" % key
|
||||
else:
|
||||
_super = super(IrAttachment, self)
|
||||
filename = _super._store_file_write(key, bin_data)
|
||||
@@ -38,7 +38,7 @@ class IrAttachment(models.Model):
|
||||
|
||||
@api.model
|
||||
def _store_file_delete(self, fname):
|
||||
if fname.startswith('s3://'):
|
||||
if fname.startswith("s3://"):
|
||||
FAKE_S3_BUCKET.pop(fname)
|
||||
else:
|
||||
super(IrAttachment, self)._store_file_delete(fname)
|
||||
|
||||
@@ -2,38 +2,41 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
|
||||
import base64
|
||||
|
||||
from odoo.tests import TransactionCase
|
||||
from odoo.modules.module import get_module_resource
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.modules.module import get_module_resource
|
||||
from odoo.tests import TransactionCase
|
||||
|
||||
|
||||
class TestFileUrlFields(TransactionCase):
|
||||
|
||||
def test_fileurl_fields(self):
|
||||
file_path = get_module_resource('test_base_fileurl_field', 'data',
|
||||
'sample.txt')
|
||||
image_path = get_module_resource('test_base_fileurl_field', 'data',
|
||||
'pattern.png')
|
||||
partner = self.env.ref('base.main_partner')
|
||||
with open(file_path, 'rb') as f:
|
||||
with open(image_path, 'rb') as i:
|
||||
partner.write({
|
||||
'url_file': base64.b64encode(f.read()),
|
||||
'url_file_fname': 'sample.txt',
|
||||
'url_image': base64.b64encode(i.read()),
|
||||
'url_image_fname': 'pattern.png',
|
||||
})
|
||||
file_path = get_module_resource("test_base_fileurl_field", "data", "sample.txt")
|
||||
image_path = get_module_resource(
|
||||
"test_base_fileurl_field", "data", "pattern.png"
|
||||
)
|
||||
partner = self.env.ref("base.main_partner")
|
||||
with open(file_path, "rb") as f:
|
||||
with open(image_path, "rb") as i:
|
||||
partner.write(
|
||||
{
|
||||
"url_file": base64.b64encode(f.read()),
|
||||
"url_file_fname": "sample.txt",
|
||||
"url_image": base64.b64encode(i.read()),
|
||||
"url_image_fname": "pattern.png",
|
||||
}
|
||||
)
|
||||
|
||||
with open(file_path, 'rb') as f:
|
||||
with open(file_path, "rb") as f:
|
||||
self.assertEqual(base64.decodebytes(partner.url_file), f.read())
|
||||
|
||||
with open(image_path, 'rb') as i:
|
||||
with open(image_path, "rb") as i:
|
||||
self.assertEqual(base64.decodebytes(partner.url_image), i.read())
|
||||
|
||||
partner2 = self.env.ref('base.partner_admin')
|
||||
with open(file_path, 'rb') as f:
|
||||
partner2 = self.env.ref("base.partner_admin")
|
||||
with open(file_path, "rb") as f:
|
||||
with self.assertRaises(ValidationError):
|
||||
partner2.write({
|
||||
'url_file': base64.b64encode(f.read()),
|
||||
'url_file_fname': 'sample.txt',
|
||||
})
|
||||
partner2.write(
|
||||
{
|
||||
"url_file": base64.b64encode(f.read()),
|
||||
"url_file_fname": "sample.txt",
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<record id="view_partner_form_inherit" model="ir.ui.view">
|
||||
<field name="name">res.partner.form.inherit</field>
|
||||
@@ -9,11 +9,15 @@
|
||||
<page name="fileurl_test" string="FileURL Test fields">
|
||||
<group string="Default widget">
|
||||
<field name="url_file" filename="url_file_fname" />
|
||||
<field name="url_file_fname" invisible="1"/>
|
||||
<field name="url_file_fname" invisible="1" />
|
||||
</group>
|
||||
<group string="Image widget">
|
||||
<field name="url_image" widget="image" filename="url_image_fname" />
|
||||
<field name="url_image_fname" invisible="1"/>
|
||||
<field
|
||||
name="url_image"
|
||||
widget="image"
|
||||
filename="url_image_fname"
|
||||
/>
|
||||
<field name="url_image_fname" invisible="1" />
|
||||
</group>
|
||||
</page>
|
||||
</xpath>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<record id="view_users_form_inherit" model="ir.ui.view">
|
||||
<field name="name">res.users.form.inherit</field>
|
||||
@@ -9,7 +9,7 @@
|
||||
<page name="fileurl_test" string="FileURL Test fields">
|
||||
<group string="Default widget">
|
||||
<field name="url_file" filename="url_file_fname" />
|
||||
<field name="url_file_fname" invisible="1"/>
|
||||
<field name="url_file_fname" invisible="1" />
|
||||
</group>
|
||||
</page>
|
||||
</xpath>
|
||||
|
||||
Reference in New Issue
Block a user