You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.9 KiB

4 years ago
4 years ago
4 years ago
  1. # © 2020 Le Filament (<http://www.le-filament.com>)
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from odoo import api, fields, models
  4. import pytz
  5. from datetime import datetime
  6. from pytz import timezone
  7. class PosTransaction(models.Model):
  8. _name = 'pos.transaction'
  9. _description = 'Table des Transactions'
  10. name = fields.Char('Ref Produit')
  11. balance_id = fields.Char('Id de la balance/caisse')
  12. qrcode = fields.Char("QRCode")
  13. ean13 = fields.Char('EAN13 Poids Produits', size=13)
  14. ean13_verif = fields.Char('EAN13 Vérification Poids', size=13)
  15. date_iso = fields.Char('Date ISO', compute="_compute_date_iso")
  16. container_ean13 = fields.Char('EAN13 Container', size=13)
  17. weight_net = fields.Float('Poids Net (en kg)', digits=(12,3))
  18. weight_tare = fields.Float('Poids Tare (en kg)', digits=(12,3))
  19. price_net = fields.Float('Prix total')
  20. price_product = fields.Float('Prix au kilo')
  21. product_id = fields.Many2one('product.product', string='Produit ID')
  22. @api.model
  23. def create_from_ui(self, transactions):
  24. # retourne la liste des ids dans le même ordre que la liste fournie
  25. transaction_ids = []
  26. for transaction in transactions:
  27. transaction_id = transaction.pop('id', False)
  28. if transaction_id:
  29. self.browse(transaction_id).write(transaction)
  30. else:
  31. transaction_id = self.create(transaction).id
  32. transaction_ids.append(transaction_id)
  33. return transaction_ids
  34. @api.depends('write_date')
  35. def _compute_date_iso(self):
  36. for transaction in self:
  37. # print("---date_iso ---", str(date_iso))
  38. if hasattr(transaction.write_date, 'isoformat'):
  39. date_iso = pytz.utc.localize(transaction.write_date).astimezone(pytz.timezone('Europe/Paris'))
  40. transaction.date_iso = date_iso.isoformat('T')[:19]