working pos again
This commit is contained in:
parent
a317315bb2
commit
312dffdad0
|
|
@ -28,7 +28,7 @@
|
|||
'assets': {
|
||||
'point_of_sale.assets': [
|
||||
'static/src/js/partner_access_popup.js',
|
||||
'static/src/js/debug.js',
|
||||
#'static/src/js/debug.js',
|
||||
],
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -9,27 +9,33 @@ _logger.info("✅ ows_models.py geladen")
|
|||
|
||||
class ResPartner(models.Model):
|
||||
_inherit = 'res.partner'
|
||||
_logger.info("✅ ows ResPartner geladen")
|
||||
ows_user_id = fields.Many2one(
|
||||
'ows.user',
|
||||
string='OWS Benutzerdaten',
|
||||
compute='_compute_ows_user',
|
||||
inverse='_inverse_ows_user',
|
||||
store=True,
|
||||
)
|
||||
|
||||
# ✳️ Related-Felder zur Verwendung im Formular
|
||||
birthday = fields.Date(related='ows_user_id.birthday', readonly=False)
|
||||
rfid_card = fields.Text(related='ows_user_id.rfid_card', readonly=False)
|
||||
security_briefing = fields.Boolean(related='ows_user_id.security_briefing', readonly=False)
|
||||
security_id = fields.Text(related='ows_user_id.security_id', readonly=False)
|
||||
_logger.info("✅ ows ResPartner geladen")
|
||||
|
||||
def _compute_ows_user(self):
|
||||
ows_user_id = fields.One2many('ows.user', 'partner_id', string="OWS Benutzerdaten")
|
||||
|
||||
# ✳️ Zugriff auf Felder aus ows.user per compute + inverse (statt related)
|
||||
birthday = fields.Date(compute='_compute_ows_user_fields', inverse='_inverse_ows_user_fields', store=False)
|
||||
rfid_card = fields.Text(compute='_compute_ows_user_fields', inverse='_inverse_ows_user_fields', store=False)
|
||||
security_briefing = fields.Boolean(compute='_compute_ows_user_fields', inverse='_inverse_ows_user_fields', store=False)
|
||||
security_id = fields.Text(compute='_compute_ows_user_fields', inverse='_inverse_ows_user_fields', store=False)
|
||||
|
||||
@api.depends('ows_user_id')
|
||||
def _compute_ows_user_fields(self):
|
||||
for partner in self:
|
||||
partner.ows_user_id = self.env['ows.user'].search(
|
||||
[('partner_id', '=', partner.id)],
|
||||
limit=1
|
||||
)
|
||||
user = partner.ows_user_id[0] if partner.ows_user_id else False
|
||||
partner.birthday = user.birthday if user else False
|
||||
partner.rfid_card = user.rfid_card if user else False
|
||||
partner.security_briefing = user.security_briefing if user else False
|
||||
partner.security_id = user.security_id if user else False
|
||||
|
||||
def _inverse_ows_user_fields(self):
|
||||
for partner in self:
|
||||
user = partner.ows_user_id[0] if partner.ows_user_id else False
|
||||
if user:
|
||||
user.birthday = partner.birthday
|
||||
user.rfid_card = partner.rfid_card
|
||||
user.security_briefing = partner.security_briefing
|
||||
user.security_id = partner.security_id
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
|
|
@ -38,13 +44,11 @@ class ResPartner(models.Model):
|
|||
self.env['ows.user'].create({'partner_id': partner.id})
|
||||
return partners
|
||||
|
||||
|
||||
machine_access_ids = fields.One2many(
|
||||
'ows.machine.access',
|
||||
'partner_id',
|
||||
string='Maschinenfreigaben'
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
machine_access_html = fields.Html(
|
||||
string="Maschinenfreigaben",
|
||||
|
|
@ -54,21 +58,9 @@ class ResPartner(models.Model):
|
|||
|
||||
@api.depends('machine_access_ids')
|
||||
def _compute_machine_access_html(self):
|
||||
"""
|
||||
Computes an HTML representation of the machine access permissions for each partner.
|
||||
The HTML is structured as a grid of machine areas, where each area contains a table
|
||||
listing the machines and whether the partner has access to them.
|
||||
|
||||
- Iterates through all machine areas and their associated machines.
|
||||
- Checks if the partner has access to each machine.
|
||||
- Generates an HTML table with a checkmark or cross icon for each machine access status.
|
||||
- Assigns the generated HTML to the `machine_access_html` field of the partner.
|
||||
"""
|
||||
areas = self.env['ows.machine.area'].search([], order="name")
|
||||
for partner in self:
|
||||
areas = self.env['ows.machine.area'].search([], order="name")
|
||||
html = """
|
||||
<div style='display: grid; grid-template-columns: repeat(3, 1fr); gap: 2rem;'>
|
||||
"""
|
||||
html = "<div style='display: grid; grid-template-columns: repeat(3, 1fr); gap: 2rem;'>"
|
||||
for area in areas:
|
||||
html += f"<div class='o_group' style='margin-bottom: 1em;'>"
|
||||
html += f"<table class='o_group o_inner_group'>"
|
||||
|
|
@ -94,14 +86,17 @@ class ResPartner(models.Model):
|
|||
html += "</div>"
|
||||
partner.machine_access_html = html
|
||||
|
||||
|
||||
@api.model
|
||||
def migrate_existing_partners(self):
|
||||
"""
|
||||
Erstellt für alle vorhandenen res.partner einen ows.user,
|
||||
wenn noch keiner existiert, und übernimmt alte vvow_* Felder.
|
||||
odoo-bin shell -d deine_datenbank
|
||||
env['res.partner'].migrate_existing_partners()
|
||||
Führt am Ende automatisch einen commit durch.
|
||||
|
||||
Verwendung in der odoo shell:
|
||||
env['res.partner'].migrate_existing_partners()
|
||||
env['ows.user'].search_count([])
|
||||
env['ows.user'].search([]).mapped('partner_id.name')
|
||||
"""
|
||||
migrated = 0
|
||||
skipped = 0
|
||||
|
|
@ -126,6 +121,9 @@ class ResPartner(models.Model):
|
|||
|
||||
_logger.info(f"[OWS Migration] ✅ Migriert: {migrated}, ❌ Übersprungen: {skipped}")
|
||||
|
||||
# 🔐 Commit am Ende
|
||||
self.env.cr.commit()
|
||||
|
||||
return {
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'display_notification',
|
||||
|
|
@ -134,7 +132,8 @@ class ResPartner(models.Model):
|
|||
'message': f"{migrated} Partner migriert, {skipped} übersprungen.",
|
||||
'sticky': False,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class OwsUser(models.Model):
|
||||
_name = 'ows.user'
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class PosOrder(models.Model):
|
|||
|
||||
training_products = self.env['ows.machine.training'].search([])
|
||||
product_map = {
|
||||
tp.product_id.product_tmpl_id.id: tp.machine_id.id
|
||||
tp.training_id.product_tmpl_id.id: tp.machine_id.id
|
||||
for tp in training_products
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,9 +2,14 @@ odoo.define('open_workshop.models', function (require) {
|
|||
"use strict";
|
||||
var models = require('point_of_sale.models');
|
||||
var field_utils = require('web.field_utils');
|
||||
|
||||
models.load_fields('res.partner', 'create_date');
|
||||
|
||||
models.load_fields('res.partner', 'birthday');
|
||||
models.load_fields('res.partner', 'security_briefing');
|
||||
models.load_fields('res.partner', 'security_id');
|
||||
models.load_fields('res.partner', 'rfid_card');
|
||||
|
||||
|
||||
});
|
||||
|
||||
odoo.define('open_workshop.partner_access_popup', function (require) {
|
||||
|
|
|
|||
|
|
@ -29,12 +29,12 @@
|
|||
|
||||
<div class='client-detail'>
|
||||
<span class='label'>Geburtstag</span>
|
||||
<t t-if='partner.ows_user_id.birthday'>
|
||||
<t t-if='partner.birthday'>
|
||||
<span class='detail client-vvow_birthday'>
|
||||
<t t-esc='partner.ows_user_id.birthday' />
|
||||
<t t-esc='partner.birthday' />
|
||||
</span>
|
||||
</t>
|
||||
<t t-if='!partner.ows_user_id.birthday'>
|
||||
<t t-if='!partner.birthday'>
|
||||
<span class='detail client-vvow_birthday empty'>N/A</span>
|
||||
</t>
|
||||
</div>
|
||||
|
|
@ -62,23 +62,23 @@
|
|||
</div>
|
||||
<div class='client-detail'>
|
||||
<span class='label'>Haftungs.</span>
|
||||
<t t-if='partner.ows_user_id.security_briefing'>
|
||||
<t t-if='partner.security_briefing'>
|
||||
<span class='detail client-details-vvow_briefing'>
|
||||
Ja
|
||||
</span>
|
||||
</t>
|
||||
<t t-if='!partner.ows_user_id.security_briefing'>
|
||||
<t t-if='!partner.security_briefing'>
|
||||
<span class='detail client-details-vvow_sec_briefing_error'>
|
||||
Nein, bitte überprüfen!
|
||||
</span>
|
||||
</t>
|
||||
<span class='label'>Id:</span>
|
||||
<t t-if='partner.ows_user_id.security_id'>
|
||||
<t t-if='partner.security_id'>
|
||||
<span class='detail client-details-vvow_security_id'>
|
||||
<t t-esc="partner.ows_user_id.security_id"/>
|
||||
<t t-esc="partner.security_id"/>
|
||||
</span>
|
||||
</t>
|
||||
<t t-if='!partner.ows_user_id.security_id'>
|
||||
<t t-if='!partner.security_id'>
|
||||
<span class='detail client-details-vvow_security_id__error'>
|
||||
Kein ID vorhanden
|
||||
</span>
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
</div>
|
||||
<div class='client-detail'>
|
||||
<span class='label'>Geburtstag</span>
|
||||
<input class='detail client-birthday' name='birthday' type='date' t-att-value='partner.ows_user_id.birthday || ""'></input>
|
||||
<input class='detail client-birthday' name='birthday' type='date' t-att-value='partner.birthday || ""'></input>
|
||||
</div>
|
||||
<div t-attf-class='client-detail #{widget.pos.pricelists.length <= 1 ? "oe_hidden" : ""}'>
|
||||
<span class='label'>Pricelist</span>
|
||||
|
|
@ -52,9 +52,9 @@
|
|||
|
||||
<div class='client-detail'>
|
||||
<span class='label'>Haftungsauschschluß</span>
|
||||
<select class='detail client-vvow_security_briefing-states needsclick' name='vvow_security_briefing'>
|
||||
<option value='true' t-att-selected="partner.ows_user_id.security_briefing ? true : undefined">Ja</option>
|
||||
<option value='' t-att-selected="!partner.ows_user_id.security_briefing ? true: undefined">Nein</option>
|
||||
<select class='detail client-vvow_security_briefing-states needsclick' name='security_briefing'>
|
||||
<option value='true' t-att-selected="partner.security_briefing ? true : undefined">Ja</option>
|
||||
<option value='' t-att-selected="!partner.security_briefing ? true: undefined">Nein</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user