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.

83 lines
3.2 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 res.container_id:
  30. today = datetime.today().isoformat('T')[:19]
  31. weight_str = str(int(res.qty * 1000))
  32. # weight_str = str(res.qty * 1000).zfill(5)
  33. prod = (res.product_id.default_code).zfill(5)
  34. ean13 = "26" + prod + weight_str.zfill(5) + "4"
  35. weight_brut_str = str(int((res.container_weight + res.qty) * 1000))
  36. ean13_verif = "2600999" + weight_brut_str.zfill(5) + "4"
  37. seller_id = self.env['product.supplierinfo'].search([
  38. ("product_tmpl_id", '=', res.product_id.product_tmpl_id.id)],
  39. limit=1)
  40. nomenclature = self.env['barcode.nomenclature'].browse(1)
  41. ean13_digit = nomenclature.sanitize_ean(ean13)
  42. ean13_verif_digit = nomenclature.sanitize_ean(ean13_verif)
  43. vals = {
  44. "date_iso": today,
  45. 'qrcode': 'https://qr.mayam.fr/' + str(res.container_id.barcode),
  46. "container_ean13": res.container_id.barcode,
  47. "product_id": res.product_id.id,
  48. "name": res.product_id.name,
  49. "price_net": res.price_subtotal,
  50. "price_product": res.price_unit,
  51. "weight_net": res.qty,
  52. "weight_tare": res.container_weight,
  53. "seller_name": seller_id.name.name,
  54. "seller_code": seller_id.product_code,
  55. "ean13": ean13_digit,
  56. "ean13_verif": ean13_verif_digit,
  57. "is_pos": True,
  58. "balance_id": res.caisse_id
  59. }
  60. self.env['pos.transaction'].create(vals)
  61. return res
  62. # ------------------------------------------------------
  63. # Actions
  64. # ------------------------------------------------------
  65. # ------------------------------------------------------
  66. # Business methods
  67. # ------------------------------------------------------