# © 2020 Le Filament () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo import api, fields, models import pytz from datetime import datetime from pytz import timezone class PosTransaction(models.Model): _name = 'pos.transaction' _description = 'Table des Transactions' name = fields.Char('Ref Produit') balance_id = fields.Char('Id de la balance/caisse') qrcode = fields.Char("QRCode") ean13 = fields.Char('EAN13 Poids Produits', size=13) ean13_verif = fields.Char('EAN13 Vérification Poids', size=13) date_iso = fields.Char('Date ISO', compute="_compute_date_iso") container_ean13 = fields.Char('EAN13 Container', size=13) weight_net = fields.Float('Poids Net (en kg)', digits=(12,3)) weight_tare = fields.Float('Poids Tare (en kg)', digits=(12,3)) price_net = fields.Float('Prix total') price_product = fields.Float('Prix au kilo') product_id = fields.Many2one('product.product', string='Produit ID') @api.model def create_from_ui(self, transactions): # retourne la liste des ids dans le même ordre que la liste fournie transaction_ids = [] for transaction in transactions: transaction_id = transaction.pop('id', False) if transaction_id: self.browse(transaction_id).write(transaction) else: transaction_id = self.create(transaction).id transaction_ids.append(transaction_id) return transaction_ids @api.depends('write_date') def _compute_date_iso(self): for transaction in self: # print("---date_iso ---", str(date_iso)) if hasattr(transaction.write_date, 'isoformat'): date_iso = pytz.utc.localize(transaction.write_date).astimezone(pytz.timezone('Europe/Paris')) transaction.date_iso = date_iso.isoformat('T')[:19]