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.

88 lines
3.5 KiB

3 years ago
3 years ago
3 years ago
  1. # Copyright 2021 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 fields, models, api
  4. from datetime import datetime
  5. class PosOrderLine(models.Model):
  6. _inherit = 'pos.order.line'
  7. # ------------------------------------------------------
  8. # Fields declaration
  9. # ------------------------------------------------------
  10. caisse_id = fields.Char('Id de la caisse')
  11. # ------------------------------------------------------
  12. # SQL Constraints
  13. # ------------------------------------------------------
  14. # ------------------------------------------------------
  15. # Default methods
  16. # ------------------------------------------------------
  17. # ------------------------------------------------------
  18. # Computed fields / Search Fields
  19. # ------------------------------------------------------
  20. # ------------------------------------------------------
  21. # Onchange / Constraints
  22. # ------------------------------------------------------
  23. # ------------------------------------------------------
  24. # CRUD methods (ORM overrides)
  25. # ------------------------------------------------------
  26. @api.model
  27. def create(self, values):
  28. res = super(PosOrderLine, self).create(values)
  29. if not res.order_id.config_id.is_balance_free:
  30. if res.container_id:
  31. today = datetime.today().isoformat('T')[:19]
  32. weight_str = str(int(res.qty * 1000))
  33. # weight_str = str(res.qty * 1000).zfill(5)
  34. if res.product_id.default_code:
  35. prod = (res.product_id.default_code).zfill(5)
  36. else:
  37. prod = "12345"
  38. ean13 = "26" + prod + weight_str.zfill(5) + "4"
  39. weight_brut_str = str(int((res.container_weight + res.qty) * 1000))
  40. ean13_verif = "2600999" + weight_brut_str.zfill(5) + "4"
  41. seller_id = self.env['product.supplierinfo'].search([
  42. ("product_tmpl_id", '=', res.product_id.product_tmpl_id.id)],
  43. limit=1)
  44. nomenclature = self.env['barcode.nomenclature'].browse(1)
  45. ean13_digit = nomenclature.sanitize_ean(ean13)
  46. ean13_verif_digit = nomenclature.sanitize_ean(ean13_verif)
  47. vals = {
  48. "date_iso": today,
  49. 'qrcode': 'https://qr.mayam.fr/' + str(res.container_id.barcode),
  50. "container_ean13": res.container_id.barcode,
  51. "product_id": res.product_id.id,
  52. "name": res.product_id.name,
  53. "price_net": res.price_subtotal,
  54. "price_product": res.price_unit,
  55. "weight_net": res.qty,
  56. "weight_tare": res.container_weight,
  57. "seller_name": seller_id.name.name,
  58. "seller_code": seller_id.product_code,
  59. "ean13": ean13_digit,
  60. "ean13_verif": ean13_verif_digit,
  61. "is_pos": True,
  62. "balance_id": res.caisse_id
  63. }
  64. self.env['pos.transaction'].create(vals)
  65. return res
  66. # ------------------------------------------------------
  67. # Actions
  68. # ------------------------------------------------------
  69. # ------------------------------------------------------
  70. # Business methods
  71. # ------------------------------------------------------