mirror of
https://gitlab.com/datalifeit/trytond-stock_product_category_location
synced 2023-12-14 04:33:11 +01:00
parent
31f5763638
commit
ac5e2fc1cf
|
@ -45,7 +45,7 @@ class ProductCategoryLocation(ModelSQL, ModelView):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _compute_sequence(table, record):
|
def _compute_sequence(table, record):
|
||||||
cursor = Transaction().cursor
|
cursor = Transaction().connection.cursor()
|
||||||
seq_sel = table.select(
|
seq_sel = table.select(
|
||||||
Max(table.sequence).as_('max_sequence'))
|
Max(table.sequence).as_('max_sequence'))
|
||||||
seq_sel.where = ProductCategoryLocation._compute_sequence_where(table, record)
|
seq_sel.where = ProductCategoryLocation._compute_sequence_where(table, record)
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
<data>
|
<data>
|
||||||
<record model="ir.ui.view" id="location_view_form">
|
<record model="ir.ui.view" id="location_view_form">
|
||||||
<field name="model">stock.location</field>
|
<field name="model">stock.location</field>
|
||||||
<field name="type">form</field>
|
|
||||||
<field name="inherit" ref="stock.location_view_form"/>
|
<field name="inherit" ref="stock.location_view_form"/>
|
||||||
<field name="name">location_form</field>
|
<field name="name">location_form</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
# copyright notices and license terms.
|
# copyright notices and license terms.
|
||||||
import unittest
|
import unittest
|
||||||
import trytond.tests.test_tryton
|
import trytond.tests.test_tryton
|
||||||
from trytond.tests.test_tryton import ModuleTestCase
|
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||||
from trytond.tests.test_tryton import POOL, DB_NAME, USER, CONTEXT
|
|
||||||
from trytond.transaction import Transaction
|
from trytond.transaction import Transaction
|
||||||
|
from trytond.pool import Pool
|
||||||
from trytond.exceptions import UserError
|
from trytond.exceptions import UserError
|
||||||
import doctest
|
import doctest
|
||||||
from trytond.tests.test_tryton import doctest_setup, doctest_teardown
|
from trytond.tests.test_tryton import doctest_setup, doctest_teardown
|
||||||
|
@ -14,41 +14,44 @@ class StockProductCategoryLocationTestCase(ModuleTestCase):
|
||||||
"""Test Stock Product Category Location module"""
|
"""Test Stock Product Category Location module"""
|
||||||
module = 'stock_product_category_location'
|
module = 'stock_product_category_location'
|
||||||
|
|
||||||
def setUp(self):
|
@with_transaction()
|
||||||
super(StockProductCategoryLocationTestCase, self).setUp()
|
|
||||||
self.location = POOL.get('stock.location')
|
|
||||||
self.category = POOL.get('product.category')
|
|
||||||
self.cat_loc = POOL.get('stock.product.category.location')
|
|
||||||
|
|
||||||
def test0010_add_category_default_location(self):
|
def test0010_add_category_default_location(self):
|
||||||
"""Add the category default location for a warehouse"""
|
"""Add the category default location for a warehouse"""
|
||||||
|
pool = Pool()
|
||||||
|
Location = pool.get('stock.location')
|
||||||
|
Category = pool.get('product.category')
|
||||||
|
CatLoc = pool.get('stock.product.category.location')
|
||||||
|
transaction = Transaction()
|
||||||
|
|
||||||
with Transaction().start(DB_NAME, USER, context=CONTEXT) as transaction:
|
storage, = Location.search([('code', '=', 'STO')])
|
||||||
storage, = self.location.search([('code', '=', 'STO')])
|
new_cat, = Category.create([{'name': 'CAT1'}])
|
||||||
new_cat, = self.category.create([{'name': 'CAT1'}])
|
cat_loc_rec = {
|
||||||
cat_loc_rec = {
|
'category': new_cat.id,
|
||||||
'category': new_cat.id,
|
'warehouse': storage.parent.id,
|
||||||
'warehouse': storage.parent.id,
|
'location': storage.id
|
||||||
'location': storage.id
|
}
|
||||||
}
|
CatLoc.create([cat_loc_rec])
|
||||||
self.cat_loc.create([cat_loc_rec])
|
transaction.commit()
|
||||||
transaction.cursor.commit()
|
|
||||||
|
|
||||||
|
@with_transaction()
|
||||||
def test0020category_location_unique(self):
|
def test0020category_location_unique(self):
|
||||||
"""Check unique error"""
|
"""Check unique error"""
|
||||||
|
pool = Pool()
|
||||||
|
Location = pool.get('stock.location')
|
||||||
|
Category = pool.get('product.category')
|
||||||
|
CatLoc = pool.get('stock.product.category.location')
|
||||||
|
|
||||||
with Transaction().start(DB_NAME, USER, context=CONTEXT):
|
storage, = Location.search([('code', '=', 'STO')])
|
||||||
storage, = self.location.search([('code', '=', 'STO')])
|
new_cat, = Category.search([('name', '=', 'CAT1')])
|
||||||
new_cat, = self.category.search([('name', '=', 'CAT1')])
|
cat_loc_rec = {
|
||||||
cat_loc_rec = {
|
'category': new_cat.id,
|
||||||
'category': new_cat.id,
|
'warehouse': storage.parent.id,
|
||||||
'warehouse': storage.parent.id,
|
'location': storage.id
|
||||||
'location': storage.id
|
}
|
||||||
}
|
with self.assertRaises(UserError) as cm:
|
||||||
with self.assertRaises(UserError) as cm:
|
CatLoc.create([cat_loc_rec])
|
||||||
self.cat_loc.create([cat_loc_rec])
|
self.assertEqual(
|
||||||
self.assertEqual(
|
cm.exception.message, 'Category and location must be unique.')
|
||||||
cm.exception.message, 'Category and location must be unique.')
|
|
||||||
|
|
||||||
|
|
||||||
def suite():
|
def suite():
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[tryton]
|
[tryton]
|
||||||
version=3.8.1
|
version=4.0.3
|
||||||
depends:
|
depends:
|
||||||
ir
|
ir
|
||||||
res
|
res
|
||||||
|
|
Loading…
Reference in a new issue