[POS-commit] r211 - Stoq2/lib/domain
Henrique Romano
henrique at async.com.br
Mon Mar 28 11:52:45 BRT 2005
Author: henrique
Date: 2005-03-28 11:52:45 -0300 (Mon, 28 Mar 2005)
New Revision: 211
Modified:
Stoq2/lib/domain/person.py
Stoq2/lib/domain/product.py
Stoq2/lib/domain/stock.py
Log:
Fix for bug #1877: Implementation of create_branch_company and
create_stock_item
Initial implementation of create_branch_company, create_stock_item and
update_stocks.
r=evandro.
Modified: Stoq2/lib/domain/person.py
===================================================================
--- Stoq2/lib/domain/person.py 2005-03-28 14:05:42 UTC (rev 210)
+++ Stoq2/lib/domain/person.py 2005-03-28 14:52:45 UTC (rev 211)
@@ -26,9 +26,10 @@
Person domain classes for Stoq applications.
"""
from mx.DateTime import DateTimeType
-from twisted.python import components
from domain import Model, attr, classref
+from IndexedCatalog.Util import EC_isinstance
+
#
# Base Domain Classes
#
@@ -228,7 +229,8 @@
_required_attrs = ['manager']
def __init__(self, person):
- #XXX: Here we have to ensure the person is a Company
+ assert EC_isinstance(person, Company), \
+ "person must to be a Company instance!"
PersonRole.__init__(self, person)
@@ -267,3 +269,17 @@
catalog = conn.get_catalog(User)
object = catalog.new(person)
return object
+
+def create_branch_company(conn, lonely, person, **kwargs):
+ if lonely:
+ object = BranchCompany(person, **kwargs)
+ else:
+ catalog = conn.get_catalog(BranchCompany)
+ object = catalog.new(person, **kwargs)
+
+ # to avoid circular reference
+ from domain.product import update_stocks
+ update_stocks(conn, object)
+
+ return object
+
Modified: Stoq2/lib/domain/product.py
===================================================================
--- Stoq2/lib/domain/product.py 2005-03-28 14:05:42 UTC (rev 210)
+++ Stoq2/lib/domain/product.py 2005-03-28 14:52:45 UTC (rev 211)
@@ -129,3 +129,16 @@
description = ''
value = 0.0
+#
+#
+#
+
+def update_stocks(conn, branch_company):
+ from domain.stock import create_stock_item
+
+ stockitem = create_stock_item(conn, 0)
+ stockitem.company = branch_company
+
+ for product in conn[Product].dump():
+ product.stocks.append(stockitem)
+
Modified: Stoq2/lib/domain/stock.py
===================================================================
--- Stoq2/lib/domain/stock.py 2005-03-28 14:05:42 UTC (rev 210)
+++ Stoq2/lib/domain/stock.py 2005-03-28 14:52:45 UTC (rev 211)
@@ -48,3 +48,16 @@
_required_attrs = ['company']
def __init__(self):
Model.__init__(self)
+
+#
+# Creation functions
+#
+
+def create_stock_item(conn, lonely, **kwargs):
+ if lonely:
+ object = StockItem(**kwargs)
+ else:
+ catalog = conn.get_catalog(StockItem)
+ object = catalog.new(**kwargs)
+ return object
+
More information about the POS-commit
mailing list