Files
public/ruodoo_sale_control/tests/test_sale_control.py

113 lines
4.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from odoo.tests import TransactionCase, tagged
@tagged('post_install', '-at_install')
class TestSaleControl(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.company = cls.env.company
cls.partner = cls.env['res.partner'].create({'name': 'Покупатель ООО'})
cls.product = cls.env['product.product'].create({
'name': 'Товар А',
'type': 'consu',
'lst_price': 100.0,
})
def _make_order(self, type_validation='normal', price_unit=100.0, qty=1):
return self.env['sale.order'].create({
'partner_id': self.partner.id,
'type_validation': type_validation,
'order_line': [(0, 0, {
'product_id': self.product.id,
'product_uom_qty': qty,
'price_unit': price_unit,
})],
})
# ------------------------------------------------------------------
def test_sku_generated_on_create(self):
product = self.env['product.product'].create({'name': 'Без артикула'})
self.assertTrue(product.default_code)
self.assertTrue(product.default_code.startswith('SKU'))
def test_sku_not_overwritten(self):
product = self.env['product.product'].create({
'name': 'Свой код', 'default_code': 'MY-CODE',
})
self.assertEqual(product.default_code, 'MY-CODE')
def test_set_sku_action(self):
old = self.product.default_code
self.product.set_sku()
self.assertNotEqual(self.product.default_code, old)
self.assertTrue(self.product.default_code.startswith('SKU'))
# ------------------------------------------------------------------
def test_wait_state_registered(self):
selection = dict(self.env['sale.order']._fields['state'].selection)
self.assertIn('wait', selection)
def test_confirm_normal_passes(self):
order = self._make_order(type_validation='normal')
order.action_confirm()
self.assertEqual(order.state, 'sale')
def test_confirm_balance_insufficient_waits(self):
# Нет кредита (баланс 0) — по балансу отгрузка не проходит.
order = self._make_order(type_validation='balance', price_unit=500.0)
order.action_confirm()
self.assertEqual(order.state, 'wait')
def test_shipment_activity_created(self):
order = self._make_order(type_validation='normal')
order.action_confirm()
activity_type = self.env.ref(
'ruodoo_sale_control.mail_activity_shipment_allowed'
)
activity = self.env['mail.activity'].search([
('res_model', '=', 'sale.order'),
('res_id', '=', order.id),
('activity_type_id', '=', activity_type.id),
])
self.assertTrue(activity)
def test_validate_all_reprocesses(self):
order = self._make_order(type_validation='balance', price_unit=500.0)
order.action_confirm()
self.assertEqual(order.state, 'wait')
# Меняем на «по подтверждению» и повторно валидируем всё.
order.type_validation = 'normal'
self.env['sale.order'].validate_all()
self.assertEqual(order.state, 'sale')
def test_price_alarm_detects_lower_price(self):
# Первая подтверждённая продажа по 100.
first = self._make_order(type_validation='normal', price_unit=100.0)
first.action_confirm()
# Новый черновик по цене ниже -> тревога.
second = self._make_order(type_validation='normal', price_unit=80.0)
second._compute_price_alarm()
self.assertTrue(second.price_alarm)
# Черновик по цене не ниже -> тревоги нет.
third = self._make_order(type_validation='normal', price_unit=120.0)
third._compute_price_alarm()
self.assertFalse(third.price_alarm)
# ------------------------------------------------------------------
def test_closed_doc_link(self):
invoice = self.env['account.move'].create({
'move_type': 'out_invoice',
'partner_id': self.partner.id,
})
doc = self.env['doc.closeddoc'].create({
'name': 'ЗД-1',
'date_doc': '2026-01-15',
'invoice_id': invoice.id,
'channel': 'scan',
})
invoice.closed_doc_id = doc
self.assertEqual(invoice.closed_doc_id, doc)
self.assertEqual(doc.invoice_id, invoice)