mirror of
https://github.com/bringout/oca-ocb-sale.git
synced 2026-04-25 21:52:01 +02:00
19.0 vanilla
This commit is contained in:
parent
79f83631d5
commit
73afc09215
6267 changed files with 1534193 additions and 1130106 deletions
|
|
@ -0,0 +1,60 @@
|
|||
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class ProductDocument(models.Model):
|
||||
_name = 'product.document'
|
||||
_description = "Product Document"
|
||||
_inherits = {
|
||||
'ir.attachment': 'ir_attachment_id',
|
||||
}
|
||||
_order = 'sequence, name'
|
||||
|
||||
ir_attachment_id = fields.Many2one(
|
||||
'ir.attachment',
|
||||
string="Related attachment",
|
||||
required=True,
|
||||
ondelete='cascade')
|
||||
|
||||
active = fields.Boolean(default=True)
|
||||
sequence = fields.Integer(default=10)
|
||||
|
||||
@api.onchange('url')
|
||||
def _onchange_url(self):
|
||||
for attachment in self:
|
||||
if attachment.type == 'url' and attachment.url and\
|
||||
not attachment.url.startswith(('https://', 'http://', 'ftp://')):
|
||||
raise ValidationError(_(
|
||||
"Please enter a valid URL.\nExample: https://www.odoo.com\n\nInvalid URL: %s",
|
||||
attachment.url
|
||||
))
|
||||
|
||||
#=== CRUD METHODS ===#
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
return super(
|
||||
ProductDocument,
|
||||
self.with_context(disable_product_documents_creation=True),
|
||||
).create(vals_list)
|
||||
|
||||
def copy_data(self, default=None):
|
||||
vals_list = super().copy_data(default=default)
|
||||
ir_default = default
|
||||
if ir_default:
|
||||
ir_fields = list(self.env['ir.attachment']._fields)
|
||||
ir_default = {field : default[field] for field in default if field in ir_fields}
|
||||
for document, vals in zip(self, vals_list):
|
||||
vals['ir_attachment_id'] = document.ir_attachment_id.with_context(
|
||||
no_document=True,
|
||||
disable_product_documents_creation=True,
|
||||
).copy(ir_default).id
|
||||
return vals_list
|
||||
|
||||
def unlink(self):
|
||||
attachments = self.ir_attachment_id
|
||||
res = super().unlink()
|
||||
return res and attachments.unlink()
|
||||
Loading…
Add table
Add a link
Reference in a new issue