[POS-commit] r6354 - in stoqlib/trunk: data/sql stoqlib/database
stoqlib/domain stoqlib/gui/wizards stoqlib/lib/test
Johan Dahlin
jdahlin at async.com.br
Tue Apr 10 10:52:56 BRT 2007
Author: jdahlin
Date: Tue Apr 10 10:52:56 2007
New Revision: 6354
Added:
stoqlib/trunk/data/sql/patch-5.sql
Modified:
stoqlib/trunk/stoqlib/database/tables.py
stoqlib/trunk/stoqlib/domain/receiving.py
stoqlib/trunk/stoqlib/gui/wizards/receivingwizard.py
stoqlib/trunk/stoqlib/lib/test/test_parameters.py
Log:
#3297: Remove ReceivingOrder IPaymentGroup implementation
Added: stoqlib/trunk/data/sql/patch-5.sql
==============================================================================
--- (empty file)
+++ stoqlib/trunk/data/sql/patch-5.sql Tue Apr 10 10:52:56 2007
@@ -0,0 +1,4 @@
+-- #3297: Remove ReceivingOrder IPaymentGroup implementation
+DROP TABLE receiving_order_adapt_to_payment_group;
+DELETE FROM abstract_payment_group where child_name = 'ReceivingOrderAdaptToPaymentGroup';
+ALTER TABLE receiving_order ALTER COLUMN purchase_id SET NOT NULL;
Modified: stoqlib/trunk/stoqlib/database/tables.py
==============================================================================
--- stoqlib/trunk/stoqlib/database/tables.py (original)
+++ stoqlib/trunk/stoqlib/database/tables.py Tue Apr 10 10:52:56 2007
@@ -136,8 +136,7 @@
('purchase', ["PurchaseOrder",
"PurchaseOrderAdaptToPaymentGroup",
"PurchaseItem"]),
- ('receiving', ["ReceivingOrder", "ReceivingOrderItem",
- "ReceivingOrderAdaptToPaymentGroup"]),
+ ('receiving', ["ReceivingOrder", "ReceivingOrderItem"]),
('devices', ["DeviceConstant",
"DeviceSettings"]),
]
Modified: stoqlib/trunk/stoqlib/domain/receiving.py
==============================================================================
--- stoqlib/trunk/stoqlib/domain/receiving.py (original)
+++ stoqlib/trunk/stoqlib/domain/receiving.py Tue Apr 10 10:52:56 2007
@@ -2,7 +2,7 @@
# vi:si:et:sw=4:sts=4:ts=4
##
-## Copyright (C) 2006 Async Open Source <http://www.async.com.br>
+## Copyright (C) 2006-2007 Async Open Source <http://www.async.com.br>
## All rights reserved
##
## This program is free software; you can redistribute it and/or modify
@@ -20,21 +20,20 @@
## Foundation, Inc., or visit: http://www.gnu.org/.
##
## Author(s): Evandro Vale Miquelito <evandro at async.com.br>
-## Author(s): Fabio Morbec <fabio at async.com.br>
+## Fabio Morbec <fabio at async.com.br>
+## Johan Dahlin <jdahlin at async.com.br>
##
""" Receiving management """
-from datetime import datetime
+import datetime
from decimal import Decimal
-from sqlobject import ForeignKey, IntCol, DateTimeCol, UnicodeCol
from kiwi.argcheck import argcheck
from kiwi.datatypes import currency
-from stoqdrivers.enum import PaymentMethodType
+from sqlobject import ForeignKey, IntCol, DateTimeCol, UnicodeCol
from stoqlib.database.columns import PriceCol, DecimalCol
from stoqlib.domain.base import Domain
-from stoqlib.domain.payment.payment import AbstractPaymentGroup
from stoqlib.domain.interfaces import IStorable, IPaymentGroup
from stoqlib.domain.purchase import PurchaseOrder
from stoqlib.lib.defaults import quantize
@@ -95,7 +94,7 @@
STATUS_CLOSED) = range(2)
status = IntCol(default=STATUS_PENDING)
- receival_date = DateTimeCol(default=datetime.now)
+ receival_date = DateTimeCol(default=datetime.datetime.now)
confirm_date = DateTimeCol(default=None)
notes = UnicodeCol(default='')
freight_total = PriceCol(default=0)
@@ -112,7 +111,7 @@
responsible = ForeignKey('PersonAdaptToUser')
supplier = ForeignKey('PersonAdaptToSupplier')
branch = ForeignKey('PersonAdaptToBranch')
- purchase = ForeignKey('PurchaseOrder', default=None)
+ purchase = ForeignKey('PurchaseOrder')
transporter = ForeignKey('PersonAdaptToTransporter', default=None)
def _create(self, id, **kw):
@@ -123,30 +122,6 @@
kw['cfop'] = sysparam(conn).DEFAULT_RECEIVING_CFOP
Domain._create(self, id, **kw)
- def _get_payment_group(self):
- conn = self.get_connection()
- group = IPaymentGroup(self, None)
- if group:
- raise ValueError("You should not have a IPaymentGroup facet "
- "defined at this point")
-
- purchase_group = IPaymentGroup(self.purchase, None)
- if self.purchase and purchase_group:
- default_method = purchase_group.default_method
- installments_number = purchase_group.installments_number
- interval_type = purchase_group.interval_type
- intervals = purchase_group.intervals
- else:
- default_method = int(PaymentMethodType.BILL)
- installments_number = 1
- interval_type = intervals = None
-
- return self.addFacet(IPaymentGroup, open_date=datetime.now(),
- default_method=default_method,
- installments_number=installments_number,
- interval_type=interval_type,
- intervals=intervals, connection=conn)
-
def confirm(self):
# Stock management
for item in self.get_items():
@@ -159,7 +134,7 @@
self.purchase.increase_quantity_received(item.sellable,
quantity)
- group = self._get_payment_group()
+ group = IPaymentGroup(self.purchase)
group.create_icmsipi_book_entry(self.cfop, self.invoice_number,
self.icms_total, self.ipi_total)
@@ -291,25 +266,6 @@
_set_surcharge_by_percentage)
-class ReceivingOrderAdaptToPaymentGroup(AbstractPaymentGroup):
-
- _inheritable = False
-
- #
- # IPaymentGroup implementation
- #
-
- def get_thirdparty(self):
- order = self.get_adapted()
- return order.supplier.person
-
- def get_group_description(self):
- order = self.get_adapted()
- return _(u'purchase receiving %s') % order.id
-
-ReceivingOrder.registerFacet(ReceivingOrderAdaptToPaymentGroup, IPaymentGroup)
-
-
@argcheck(PurchaseOrder, ReceivingOrder)
def get_receiving_items_by_purchase_order(purchase_order, receiving_order):
"""Returns a list of receiving items based on a list of purchase items
Modified: stoqlib/trunk/stoqlib/gui/wizards/receivingwizard.py
==============================================================================
--- stoqlib/trunk/stoqlib/gui/wizards/receivingwizard.py (original)
+++ stoqlib/trunk/stoqlib/gui/wizards/receivingwizard.py Tue Apr 10 10:52:56 2007
@@ -2,7 +2,7 @@
# vi:si:et:sw=4:sts=4:ts=4
##
-## Copyright (C) 2006 Async Open Source <http://www.async.com.br>
+## Copyright (C) 2006-2007 Async Open Source <http://www.async.com.br>
## All rights reserved
##
## This program is free software; you can redistribute it and/or modify
@@ -20,7 +20,8 @@
## Foundation, Inc., or visit: http://www.gnu.org/.
##
## Author(s): Evandro Vale Miquelito <evandro at async.com.br>
-## Author(s): Fabio Morbec <fabio at async.com.br>
+## Fabio Morbec <fabio at async.com.br>
+## Johan Dahlin <jdahlin at async.com.br>
##
##
""" Receiving wizard definition """
@@ -52,6 +53,9 @@
_ = stoqlib_gettext
+# Workaround, so PurchaseSelectionStep does not complain about empty model
+class _FakeReceivingOrder(object):
+ pass
#
# Wizard Steps
@@ -61,7 +65,7 @@
class PurchaseSelectionStep(WizardEditorStep):
gladefile = 'PurchaseSelectionStep'
size = (800, 450)
- model_type = ReceivingOrder
+ model_type = _FakeReceivingOrder
def __init__(self, wizard, conn, model):
self._next_step = None
@@ -120,11 +124,22 @@
def next_step(self):
selected = self.orders.get_selected()
- purchase = PurchaseOrder.get(selected.id, connection=self.conn)
+ purchase = selected.purchase
+
+ # We cannot create the model in the wizard since we haven't
+ # selected a PurchaseOrder yet which ReceivingOrder depends on
+ # Create the order here since this is the first place where we
+ # actually have a purchase selected
+ if not self.wizard.model:
+ self.wizard.model = self.model = ReceivingOrder(
+ responsible=get_current_user(self.conn),
+ supplier=None, invoice_number=None,
+ branch=None, purchase=purchase,
+ connection=self.conn)
# Remove all the items added previously, used if we hit back
# at any point in the wizard.
- if self.model.purchase and self.model.purchase != purchase:
+ if self.model.purchase != purchase:
self.model.remove_items()
# This forces ReceivingOrderProductStep to create a new model
self._next_step = None
@@ -183,8 +198,8 @@
if not selected:
raise ValueError('You should have one order selected '
'at this point, got nothing')
- order = PurchaseOrder.get(selected.id, connection=self.conn)
- run_dialog(PurchaseDetailsDialog, self, self.conn, model=order)
+ run_dialog(PurchaseDetailsDialog, self, self.conn,
+ model=selected.purchase)
class ReceivingOrderProductStep(SellableItemStep):
@@ -298,22 +313,18 @@
size = (750, 560)
def __init__(self, conn):
- model = self._create_model(conn)
- first_step = PurchaseSelectionStep(self, conn, model)
- BaseWizard.__init__(self, conn, first_step, model)
+ self.model = None
+ first_step = PurchaseSelectionStep(self, conn,
+ _FakeReceivingOrder())
+ BaseWizard.__init__(self, conn, first_step, self.model)
self.next_button.set_sensitive(False)
- def _create_model(self, conn):
- current_user = get_current_user(conn)
- return ReceivingOrder(responsible=current_user, supplier=None,
- invoice_number=None, branch=None,
- connection=conn)
-
#
# WizardStep hooks
#
def finish(self):
+ assert self.model
assert self.model.branch
if not self.model.get_valid():
Modified: stoqlib/trunk/stoqlib/lib/test/test_parameters.py
==============================================================================
--- stoqlib/trunk/stoqlib/lib/test/test_parameters.py (original)
+++ stoqlib/trunk/stoqlib/lib/test/test_parameters.py Tue Apr 10 10:52:56 2007
@@ -265,17 +265,20 @@
responsible = person.addFacet(IUser, connection=self.trans,
password='asdfgh', profile=profile,
username='craudio')
+ purchase = self.create_purchase_order()
receiving_order = ReceivingOrder(responsible=responsible,
branch=branch,
connection=self.trans,
invoice_number=876,
- supplier=None)
+ supplier=None,
+ purchase=purchase)
param2 = self.sparam.DEFAULT_SALES_CFOP
receiving_order2 = ReceivingOrder(responsible=responsible,
cfop=param2, branch=branch,
connection=self.trans,
invoice_number=1231,
- supplier=None)
+ supplier=None,
+ purchase=purchase)
self.assertEqual(param, receiving_order.cfop)
self.failIfEqual(param, receiving_order2.cfop)
More information about the POS-commit
mailing list