[FIX] point_of_sale: Correctly delete linked pos_printer to iot_box

Current behavior:
You couldn't delete an iot_box if a pos_printer was linked to it.
You always get a validation error saying that "Proxy IP cannot be empty"
To fix this we first want to check that the device_id linked to the
printer still exists. To do this we need to move the constraint to the
pos_iot module (because the device_id field is defined there)

Steps to reproduce:
- Install pos_iot
- Activate preparation printer in POS
- Create a printer and link it to an iot_box device
- Try to delete the iot_box

opw-3597370

closes odoo/odoo#150502

X-original-commit: 7b41e51043c1f80971f6cc698876f8bda35f07ef
Related: odoo/enterprise#54874
Signed-off-by: Robin Engels (roen) <roen@odoo.com>
This commit is contained in:
roen-odoo
2024-01-23 16:01:47 +00:00
parent 72c4a2352c
commit d45e933a89
+1 -8
View File
@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models, api, _
from odoo.exceptions import ValidationError
from odoo import fields, models
class PosPrinter(models.Model):
@@ -14,9 +13,3 @@ class PosPrinter(models.Model):
selection=[('iot', ' Use a printer connected to the IoT Box')])
proxy_ip = fields.Char('Proxy IP Address', help="The IP Address or hostname of the Printer's hardware proxy")
product_categories_ids = fields.Many2many('pos.category', 'printer_category_rel', 'printer_id', 'category_id', string='Printed Product Categories')
@api.constrains('proxy_ip')
def _constrains_proxy_ip(self):
for record in self:
if record.printer_type == 'iot' and not record.proxy_ip:
raise ValidationError(_("Proxy IP cannot be empty."))