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.

82 lines
3.1 KiB

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