Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] base_delivery_carrier_label test decorators #862

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 36 additions & 30 deletions base_delivery_carrier_label/tests/carrier_label_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,75 +10,81 @@ class CarrierLabelCase(TransactionCase):
to return the carrier you want to test"""

@classmethod
def setUpClass(self):
super().setUpClass(self)
self._create_order_picking()
def setUpClass(cls):
super().setUpClass()
cls._create_order_picking()

@property
def transfer_in_setup(self):
return True

def _create_order_picking(self):
@classmethod
def _create_order_picking(cls):
"""Create a sale order and deliver the picking"""
self.order = self.env["sale.order"].create(self._sale_order_data())
for product in self.order.mapped("order_line.product_id"):
self.env["stock.quant"].with_context(inventory_mode=True).create(
cls.order = cls.env["sale.order"].create(cls._sale_order_data())
for product in cls.order.mapped("order_line.product_id"):
cls.env["stock.quant"].with_context(inventory_mode=True).create(
{
"product_id": product.id,
"location_id": self.order.warehouse_id.lot_stock_id.id,
"location_id": cls.order.warehouse_id.lot_stock_id.id,
"inventory_quantity": sum(
self.order.mapped("order_line.product_uom_qty")
cls.order.mapped("order_line.product_uom_qty")
),
}
)._apply_inventory()
self.order.action_confirm()
self.picking = self.order.picking_ids
self.picking.write(self._picking_data())
if self.transfer_in_setup:
self._transfer_order_picking()

def _transfer_order_picking(self):
self.env["stock.immediate.transfer"].create(
{"pick_ids": [(6, 0, self.picking.ids)]}
cls.order.action_confirm()
cls.picking = cls.order.picking_ids
cls.picking.write(cls._picking_data())
if cls.transfer_in_setup:
cls._transfer_order_picking()

@classmethod
def _transfer_order_picking(cls):
cls.env["stock.immediate.transfer"].create(
{"pick_ids": [(6, 0, cls.picking.ids)]}
).process()

def _get_carrier(self):
@classmethod
def _get_carrier(cls):
"""Return the carrier to test"""
raise NotImplementedError()

def _sale_order_data(self):
@classmethod
def _sale_order_data(cls):
"""Return a values dict to create a sale order"""
return {
"partner_id": self.env["res.partner"].create(self._partner_data()).id,
"order_line": [(0, 0, data) for data in self._order_line_data()],
"carrier_id": self._get_carrier().id,
"partner_id": cls.env["res.partner"].create(cls._partner_data()).id,
"order_line": [(0, 0, data) for data in cls._order_line_data()],
"carrier_id": cls._get_carrier().id,
}

def _partner_data(self):
@classmethod
def _partner_data(cls):
"""Return a values dict to create a partner"""
return {
"name": "Carrier label test customer",
}

def _order_line_data(self):
@classmethod
def _order_line_data(cls):
"""Return a list of value dicts to create order lines"""
return [
{
"product_id": self.env["product.product"]
.create(self._product_data())
.id,
"product_id": cls.env["product.product"].create(cls._product_data()).id,
"product_uom_qty": 1,
}
]

def _product_data(self):
@classmethod
def _product_data(cls):
"""Return a values dict to create a product"""
return {
"name": "Carrier test product",
"type": "product",
}

def _picking_data(self):
@classmethod
def _picking_data(cls):
"""Return a values dict to be written to the picking in order to set
carrier options"""
return {}
Expand Down
Loading