common.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # -*- coding: utf-8 -*-
  2. from datetime import timedelta
  3. from odoo import fields
  4. from odoo.addons.stock.tests.common2 import TestStockCommon
  5. from odoo import tools
  6. from odoo.modules.module import get_module_resource
  7. class PurchaseTestCommon(TestStockCommon):
  8. def _create_make_procurement(self, product, product_qty, date_planned=False):
  9. ProcurementGroup = self.env['procurement.group']
  10. order_values = {
  11. 'warehouse_id': self.warehouse_1,
  12. 'action': 'pull_push',
  13. 'date_planned': date_planned or fields.Datetime.to_string(fields.datetime.now() + timedelta(days=10)), # 10 days added to current date of procurement to get future schedule date and order date of purchase order.
  14. 'group_id': self.env['procurement.group'],
  15. }
  16. return ProcurementGroup.run([self.env['procurement.group'].Procurement(
  17. product, product_qty, self.uom_unit, self.warehouse_1.lot_stock_id,
  18. product.name, '/', self.env.company, order_values)
  19. ])
  20. @classmethod
  21. def setUpClass(cls):
  22. super(PurchaseTestCommon, cls).setUpClass()
  23. cls.env.ref('stock.route_warehouse0_mto').active = True
  24. cls.route_buy = cls.warehouse_1.buy_pull_id.route_id.id
  25. cls.route_mto = cls.warehouse_1.mto_pull_id.route_id.id
  26. # Update product_1 with type, route and Delivery Lead Time
  27. cls.product_1.write({
  28. 'type': 'product',
  29. 'route_ids': [(6, 0, [cls.route_buy, cls.route_mto])],
  30. 'seller_ids': [(0, 0, {'partner_id': cls.partner_1.id, 'delay': 5})]})
  31. cls.t_shirt = cls.env['product.product'].create({
  32. 'name': 'T-shirt',
  33. 'description': 'Internal Notes',
  34. 'route_ids': [(6, 0, [cls.route_buy, cls.route_mto])],
  35. 'seller_ids': [(0, 0, {'partner_id': cls.partner_1.id, 'delay': 5})]
  36. })
  37. # Update product_2 with type, route and Delivery Lead Time
  38. cls.product_2.write({
  39. 'type': 'product',
  40. 'route_ids': [(6, 0, [cls.route_buy, cls.route_mto])],
  41. 'seller_ids': [(0, 0, {'partner_id': cls.partner_1.id, 'delay': 2})]})
  42. cls.res_users_purchase_user = cls.env['res.users'].create({
  43. 'company_id': cls.env.ref('base.main_company').id,
  44. 'name': "Purchase User",
  45. 'login': "pu",
  46. 'email': "purchaseuser@yourcompany.com",
  47. 'groups_id': [(6, 0, [cls.env.ref('purchase.group_purchase_user').id])],
  48. })