def _create_transaction(store, till_entry): # Dont create till entries for sangrias/suprimentos as those are really tied to the # old ECF behaivour (where *all* the sales values are added to the till). If we # create transactions for those operations, the value would be duplicated when the # payment is finally payed. if not till_entry.payment: return if till_entry.value > 0: operation_type = AccountTransaction.TYPE_IN source_account = sysparam.get_object_id('IMBALANCE_ACCOUNT') dest_account = sysparam.get_object_id('TILLS_ACCOUNT') else: operation_type = AccountTransaction.TYPE_OUT source_account = sysparam.get_object_id('TILLS_ACCOUNT') dest_account = sysparam.get_object_id('IMBALANCE_ACCOUNT') AccountTransaction(description=till_entry.description, source_account_id=source_account, account_id=dest_account, value=abs(till_entry.value), code=str(till_entry.identifier), date=TransactionTimestamp(), store=store, payment=till_entry.payment, operation_type=operation_type)
def _create_transaction(store, till_entry): AccountTransaction(description=till_entry.description, source_account_id=sysparam.get_object_id('IMBALANCE_ACCOUNT'), account_id=sysparam.get_object_id('TILLS_ACCOUNT'), value=till_entry.value, code=unicode(till_entry.identifier), date=TransactionTimestamp(), store=store, payment=till_entry.payment)
def create_model(self, store): self._model_created = True sellable = Sellable(store=store) sellable.tax_constant_id = sysparam.get_object_id('DEFAULT_PRODUCT_TAX_CONSTANT') sellable.unit_id = sysparam.get_object_id('SUGGESTED_UNIT') model = Product(store=store, sellable=sellable) # FIXME: Instead of creating and then removing, we should only create # the Storable if the user chooses to do so, but due to the way the # editor is implemented, it is not that easy. Change this once we write # the new product editor. Storable(product=model, store=store) return model
def create_model(self, store): self._model_created = True sellable = Sellable(store=store) model = Product(store=store, sellable=sellable) no_storable = [Product.TYPE_WITHOUT_STOCK, Product.TYPE_PACKAGE] if not self._product_type in no_storable: storable = Storable(product=model, store=store) if self._product_type == Product.TYPE_BATCH: storable.is_batch = True elif self._product_type == Product.TYPE_WITHOUT_STOCK: model.manage_stock = False elif self._product_type == Product.TYPE_CONSIGNED: model.consignment = True elif self._product_type == Product.TYPE_GRID: model.is_grid = True # Configurable products should not manage stock model.manage_stock = False elif self._product_type == Product.TYPE_PACKAGE: model.is_package = True # Package products should not manage stock model.manage_stock = False if self._template is not None: sellable.tax_constant = self._template.sellable.tax_constant sellable.unit = self._template.sellable.unit sellable.category = self._template.sellable.category sellable.base_price = self._template.sellable.base_price sellable.cost = self._template.sellable.cost model.manufacturer = self._template.manufacturer model.brand = self._template.brand model.family = self._template.family model.ncm = self._template.ncm model.icms_template = self._template.icms_template model.ipi_template = self._template.ipi_template for product_attr in self._template.attributes: ProductAttribute(store=self.store, product_id=model.id, attribute_id=product_attr.attribute.id) for supplier_info in self._template.suppliers: ProductSupplierInfo( store=self.store, product=model, supplier=supplier_info.supplier) else: sellable.tax_constant_id = sysparam.get_object_id( 'DEFAULT_PRODUCT_TAX_CONSTANT') sellable.unit_id = sysparam.get_object_id('SUGGESTED_UNIT') return model
def create_model(self, store): self._model_created = True sellable = Sellable(store=store) model = Product(store=store, sellable=sellable) no_storable = [Product.TYPE_WITHOUT_STOCK, Product.TYPE_PACKAGE] if not self._product_type in no_storable: storable = Storable(product=model, store=store) if self._product_type == Product.TYPE_BATCH: storable.is_batch = True elif self._product_type == Product.TYPE_WITHOUT_STOCK: model.manage_stock = False elif self._product_type == Product.TYPE_CONSIGNED: model.consignment = True elif self._product_type == Product.TYPE_GRID: model.is_grid = True # Configurable products should not manage stock model.manage_stock = False elif self._product_type == Product.TYPE_PACKAGE: model.is_package = True # Package products should not manage stock model.manage_stock = False if self._template is not None: sellable.tax_constant = self._template.sellable.tax_constant sellable.unit = self._template.sellable.unit sellable.category = self._template.sellable.category sellable.base_price = self._template.sellable.base_price sellable.cost = self._template.sellable.cost model.manufacturer = self._template.manufacturer model.brand = self._template.brand model.family = self._template.family model.ncm = self._template.ncm model.icms_template = self._template.icms_template model.ipi_template = self._template.ipi_template for product_attr in self._template.attributes: ProductAttribute(store=self.store, product_id=model.id, attribute_id=product_attr.attribute.id) for supplier_info in self._template.suppliers: ProductSupplierInfo(store=self.store, product=model, supplier=supplier_info.supplier) else: sellable.tax_constant_id = sysparam.get_object_id( 'DEFAULT_PRODUCT_TAX_CONSTANT') sellable.unit_id = sysparam.get_object_id('SUGGESTED_UNIT') return model
def create_from_payment(cls, payment, account=None): """Create a new transaction based on a |payment|. It's normally used when creating a transaction which represents a payment, for instance when you receive a bill or a check from a |client| which will enter a |bankaccount|. :param payment: the |payment| to create the transaction for. :param account: |account| where this transaction will arrive, or ``None`` :returns: the transaction """ if not payment.is_paid(): raise PaymentError(_("Payment needs to be paid")) store = payment.store value = payment.paid_value if payment.is_outpayment(): value = -value return cls(source_account_id=sysparam.get_object_id('IMBALANCE_ACCOUNT'), account=account or payment.method.destination_account, value=value, description=payment.description, code=unicode(payment.identifier), date=payment.paid_date, store=store, payment=payment)
def create_account_transaction(self, account=None, value=1, source=None, incoming=False): from stoqlib.domain.account import AccountTransaction if account is None: account = self.create_account() if source: source_id = source.id else: source_id = sysparam.get_object_id('IMBALANCE_ACCOUNT') if incoming: operation_type = AccountTransaction.TYPE_IN else: operation_type = AccountTransaction.TYPE_OUT return AccountTransaction( description=u"Test Account Transaction", code=u"Code", date=localnow(), value=value, account=account, source_account_id=source_id, operation_type=operation_type, store=self.store)
def create_model(self, store): tax_constant = SellableTaxConstant.get_by_type(TaxType.SERVICE, self.store) sellable = Sellable(description=u"", price=currency(0), store=store) sellable.tax_constant = tax_constant sellable.unit_id = sysparam.get_object_id("SUGGESTED_UNIT") model = Service(sellable=sellable, store=store) return model
def remove(self, store): """Remove the current account. This updates all transactions which refers to this account and removes them. :param store: a store """ if not self.can_remove(): raise TypeError("Account %r cannot be removed" % (self, )) imbalance_account_id = sysparam.get_object_id('IMBALANCE_ACCOUNT') for transaction in store.find(AccountTransaction, account=self): transaction.account_id = imbalance_account_id store.flush() for transaction in store.find(AccountTransaction, source_account=self): transaction.source_account_id = imbalance_account_id store.flush() bank = self.bank if bank: for option in bank.options: store.remove(option) store.remove(bank) self.store.remove(self)
def create_for_receiving_order(cls, receiving_order): store = receiving_order.store current_user = get_current_user(store) employee = current_user.person.employee cfop_id = sysparam.get_object_id('DEFAULT_STOCK_DECREASE_CFOP') return_stock_decrease = cls(store=store, receiving_order=receiving_order, branch=get_current_branch(store), responsible=current_user, removed_by=employee, cfop_id=cfop_id) for receiving_item in receiving_order.get_items(with_children=False): if receiving_item.is_totally_returned(): # Exclude items already totally returned continue if receiving_item.children_items.count(): for child in receiving_item.children_items: StockDecreaseItem.create_for_receiving_item( return_stock_decrease, child) else: StockDecreaseItem.create_for_receiving_item( return_stock_decrease, receiving_item) return return_stock_decrease
def create_for_receiving_order(cls, receiving_order): store = receiving_order.store current_user = get_current_user(store) employee = current_user.person.employee cfop_id = sysparam.get_object_id('DEFAULT_STOCK_DECREASE_CFOP') return_stock_decrease = cls( store=store, receiving_order=receiving_order, branch=get_current_branch(store), responsible=current_user, removed_by=employee, cfop_id=cfop_id) for receiving_item in receiving_order.get_items(with_children=False): if receiving_item.is_totally_returned(): # Exclude items already totally returned continue if receiving_item.children_items.count(): for child in receiving_item.children_items: StockDecreaseItem.create_for_receiving_item( return_stock_decrease, child) else: StockDecreaseItem.create_for_receiving_item(return_stock_decrease, receiving_item) return return_stock_decrease
def create_model(self, store): self._model_created = True sellable = Sellable(store=store) sellable.tax_constant_id = sysparam.get_object_id('DEFAULT_PRODUCT_TAX_CONSTANT') sellable.unit_id = sysparam.get_object_id('SUGGESTED_UNIT') model = Product(store=store, sellable=sellable) if self._product_type != Product.TYPE_WITHOUT_STOCK: storable = Storable(product=model, store=store) if self._product_type == Product.TYPE_BATCH: storable.is_batch = True elif self._product_type == Product.TYPE_WITHOUT_STOCK: model.manage_stock = False elif self._product_type == Product.TYPE_CONSIGNED: model.consignment = True return model
def create_model(self, store): tax_constant = SellableTaxConstant.get_by_type(TaxType.SERVICE, self.store) sellable = Sellable(description=u'', price=currency(0), store=store) sellable.tax_constant = tax_constant sellable.unit_id = sysparam.get_object_id('SUGGESTED_UNIT') model = Service(sellable=sellable, store=store) return model
def _create_transaction(store, till_entry): if till_entry.value > 0: operation_type = AccountTransaction.TYPE_IN source_account = sysparam.get_object_id('IMBALANCE_ACCOUNT') dest_account = sysparam.get_object_id('TILLS_ACCOUNT') else: operation_type = AccountTransaction.TYPE_OUT source_account = sysparam.get_object_id('TILLS_ACCOUNT') dest_account = sysparam.get_object_id('IMBALANCE_ACCOUNT') AccountTransaction(description=till_entry.description, source_account_id=source_account, account_id=dest_account, value=abs(till_entry.value), code=str(till_entry.identifier), date=TransactionTimestamp(), store=store, payment=till_entry.payment, operation_type=operation_type)
def _create_model(self, store): branch = api.get_current_branch(store) user = api.get_current_user(store) employee = user.person.employee cfop_id = sysparam.get_object_id('DEFAULT_STOCK_DECREASE_CFOP') return StockDecrease(responsible=user, removed_by=employee, branch=branch, status=StockDecrease.STATUS_INITIAL, cfop_id=cfop_id, store=store)
def _create_model(self, store): supplier_id = sysparam.get_object_id('SUGGESTED_SUPPLIER') branch = api.get_current_branch(store) status = PurchaseOrder.ORDER_QUOTING group = PaymentGroup(store=store) return PurchaseOrder(supplier_id=supplier_id, branch=branch, status=status, expected_receival_date=None, responsible=api.get_current_user(store), group=group, store=store)
def _create_model(self, store): supplier_id = sysparam.get_object_id('SUGGESTED_SUPPLIER') branch = api.get_current_branch(store) group = PaymentGroup(store=store) status = PurchaseOrder.ORDER_PENDING return PurchaseOrder(supplier_id=supplier_id, responsible=api.get_current_user(store), branch=branch, status=status, group=group, store=store)
def _create_model(self, store): user = api.get_current_user(store) salesperson = user.person.salesperson return Sale(coupon_id=None, status=Sale.STATUS_QUOTE, salesperson=salesperson, branch=api.get_current_branch(store), group=PaymentGroup(store=store), cfop_id=sysparam.get_object_id('DEFAULT_SALES_CFOP'), operation_nature=sysparam.get_string('DEFAULT_OPERATION_NATURE'), store=store)
def before_start(self, store): account = store.find(Account, code=str(self.tp.account_id)).one() if account is None: account = Account(description=self.get_account_id(), code=str(self.tp.account_id), account_type=Account.TYPE_BANK, parent=sysparam.get_object( store, 'BANKS_ACCOUNT'), store=store) self.account_id = account.id self.source_account_id = sysparam.get_object_id('IMBALANCE_ACCOUNT') self.skipped = 0
def before_start(self, store): account = store.find(Account, code=unicode(self.tp.account_id)).one() if account is None: account = Account(description=self.get_account_id(), code=unicode(self.tp.account_id), account_type=Account.TYPE_BANK, parent=sysparam.get_object(store, 'BANKS_ACCOUNT'), store=store) self.account_id = account.id self.source_account_id = sysparam.get_object_id('IMBALANCE_ACCOUNT') self.skipped = 0
def process_one(self, data, fields, store): person = store.find(Person, name=data.branch_name).one() if person is None or person.branch is None: raise ValueError(u"%s is not a valid branch" % (data.branch_name, )) branch = person.branch station = store.find(BranchStation).any() user = store.find(LoginUser).any() person = store.find(Person, name=data.client_name).one() if person is None or person.client is None: raise ValueError(u"%s is not a valid client" % (data.client_name, )) client = person.client person = store.find(Person, name=data.salesperson_name).one() if person is None or person.sales_person is None: raise ValueError(u"%s is not a valid sales person" % (data.salesperson_name, )) salesperson = person.sales_person group = PaymentGroup(store=store) sale = Sale(client=client, open_date=self.parse_date(data.open_date), coupon_id=int(data.coupon_id), salesperson=salesperson, branch=branch, station=station, cfop_id=sysparam.get_object_id('DEFAULT_SALES_CFOP'), group=group, store=store) total_price = 0 for product in self.parse_multi(Product, data.product_list, store): sale.add_sellable(product.sellable) total_price += product.sellable.price sale.order(user) method = PaymentMethod.get_by_name(store, data.payment_method) method.create_payment(branch, station, Payment.TYPE_IN, group, total_price, due_date=self.parse_date(data.due_date)) sale.confirm(user) # XXX: The payments are paid automatically when a sale is confirmed. # So, we will change all the payment paid_date to the same date # as open_date, then we can test the reports properly. for payment in sale.payments: payment.open_date = sale.open_date if payment.is_paid(): p = store.fetch(payment) p.paid_date = self.parse_date(data.open_date)
def _create_transaction(store, till_entry): if till_entry.value > 0: operation_type = AccountTransaction.TYPE_IN source_account = sysparam.get_object_id("IMBALANCE_ACCOUNT") dest_account = sysparam.get_object_id("TILLS_ACCOUNT") else: operation_type = AccountTransaction.TYPE_OUT source_account = sysparam.get_object_id("TILLS_ACCOUNT") dest_account = sysparam.get_object_id("IMBALANCE_ACCOUNT") AccountTransaction( description=till_entry.description, source_account_id=source_account, account_id=dest_account, value=abs(till_entry.value), code=unicode(till_entry.identifier), date=TransactionTimestamp(), store=store, payment=till_entry.payment, operation_type=operation_type, )
def create_account_transaction(self, account=None, value=1): from stoqlib.domain.account import AccountTransaction if account is None: account = self.create_account() return AccountTransaction( description=u"Test Account Transaction", code=u"Code", date=localnow(), value=value, account=account, source_account_id=sysparam.get_object_id('IMBALANCE_ACCOUNT'), store=self.store)
def _create_model(self, store): user = api.get_current_user(store) salesperson = user.person.sales_person return Sale( coupon_id=None, status=Sale.STATUS_QUOTE, salesperson=salesperson, branch=api.get_current_branch(store), group=PaymentGroup(store=store), cfop_id=sysparam.get_object_id('DEFAULT_SALES_CFOP'), operation_nature=sysparam.get_string('DEFAULT_OPERATION_NATURE'), store=store)
def __init__(self): super(ProductImporter, self).__init__() default_store = get_default_store() suppliers = default_store.find(Supplier) if not suppliers.count(): raise ValueError(u"You must have at least one suppliers on your " u"database at this point.") self.supplier = suppliers[0] self.units = {} for unit in default_store.find(SellableUnit): self.units[unit.description] = unit self.tax_constant_id = sysparam.get_object_id("DEFAULT_PRODUCT_TAX_CONSTANT") self._code = 1
def get_pixbuf(self, model): kind = model.kind if kind == 'payable': pixbuf = self._pixbuf_payable elif kind == 'receivable': pixbuf = self._pixbuf_receivable elif kind == 'account': till_account_id = sysparam.get_object_id('TILLS_ACCOUNT') if model.matches(till_account_id): pixbuf = self._pixbuf_till else: pixbuf = self._pixbuf_money else: return None return pixbuf
def __init__(self): super(ProductImporter, self).__init__() default_store = get_default_store() suppliers = default_store.find(Supplier) if not suppliers.count(): raise ValueError(u'You must have at least one suppliers on your ' u'database at this point.') self.supplier = suppliers[0] self.units = {} for unit in default_store.find(SellableUnit): self.units[unit.description] = unit self.tax_constant_id = sysparam.get_object_id( 'DEFAULT_PRODUCT_TAX_CONSTANT') self._code = 1
def _create_model(self, store): if self.receiving_order: return StockDecrease.create_for_receiving_order(self.receiving_order) branch = api.get_current_branch(store) user = api.get_current_user(store) employee = user.person.employee cfop_id = sysparam.get_object_id('DEFAULT_STOCK_DECREASE_CFOP') stock_decrease = StockDecrease(store=store, responsible=user, removed_by=employee, branch=branch, status=StockDecrease.STATUS_INITIAL, cfop_id=cfop_id) stock_decrease.invoice.operation_nature = self.title return stock_decrease
def _create_model(self, store): if self.receiving_order: return StockDecrease.create_for_receiving_order( self.receiving_order) branch = api.get_current_branch(store) user = api.get_current_user(store) employee = user.person.employee cfop_id = sysparam.get_object_id('DEFAULT_STOCK_DECREASE_CFOP') stock_decrease = StockDecrease(store=store, responsible=user, removed_by=employee, branch=branch, status=StockDecrease.STATUS_INITIAL, cfop_id=cfop_id) stock_decrease.invoice.operation_nature = self.title return stock_decrease
def process_one(self, data, fields, store): person = store.find(Person, name=data.branch_name).one() if person is None or person.branch is None: raise ValueError(u"%s is not a valid branch" % ( data.branch_name, )) branch = person.branch person = store.find(Person, name=data.client_name).one() if person is None or person.client is None: raise ValueError(u"%s is not a valid client" % ( data.client_name, )) client = person.client person = store.find(Person, name=data.salesperson_name).one() if person is None or person.sales_person is None: raise ValueError(u"%s is not a valid sales person" % ( data.salesperson_name, )) salesperson = person.sales_person group = PaymentGroup(store=store) sale = Sale(client=client, open_date=self.parse_date(data.open_date), coupon_id=int(data.coupon_id), invoice_number=int(data.coupon_id), salesperson=salesperson, branch=branch, cfop_id=sysparam.get_object_id('DEFAULT_SALES_CFOP'), group=group, store=store) total_price = 0 for product in self.parse_multi(Product, data.product_list, store): sale.add_sellable(product.sellable) total_price += product.sellable.price sale.order() method = PaymentMethod.get_by_name(store, data.payment_method) method.create_payment(Payment.TYPE_IN, group, branch, total_price, self.parse_date(data.due_date)) sale.confirm() # XXX: The payments are paid automatically when a sale is confirmed. # So, we will change all the payment paid_date to the same date # as open_date, then we can test the reports properly. for payment in sale.payments: if payment.is_paid(): p = store.fetch(payment) p.paid_date = self.parse_date(data.open_date)
def reverse_entry(self, invoice_number, iss_value=None, icms_value=None, ipi_value=None): store = self.store icms_value = icms_value if icms_value is not None else self.icms_value iss_value = iss_value if iss_value is not None else self.iss_value ipi_value = ipi_value if ipi_value is not None else self.ipi_value return FiscalBookEntry( entry_type=self.entry_type, iss_value=iss_value, icms_value=icms_value, ipi_value=ipi_value, cfop_id=sysparam.get_object_id('DEFAULT_SALES_CFOP'), branch=self.branch, invoice_number=invoice_number, drawee=self.drawee, is_reversal=True, payment_group=self.payment_group, store=store)
def create_sellable(self, price=None, product=True, description=u'Description', code=u''): from stoqlib.domain.product import Product from stoqlib.domain.service import Service from stoqlib.domain.sellable import Sellable tax_constant_id = sysparam.get_object_id('DEFAULT_PRODUCT_TAX_CONSTANT') if price is None: price = 10 sellable = Sellable(cost=125, price=price, description=description, store=self.store) sellable.code = code sellable.tax_constant_id = tax_constant_id if product: Product(sellable=sellable, store=self.store) else: Service(sellable=sellable, store=self.store) return sellable
def insert_initial(self, store, edited_account=None): """ Insert accounts and parent accounts in a ObjectTree. :param store: a store :param edited_account: If not None, this is the account being edited. In this case, this acount (and its decendents) will not be shown in the account tree. """ till_id = sysparam.get_object_id('TILLS_ACCOUNT') if self.create_mode and edited_account: accounts = list( store.find(AccountView, AccountView.id != edited_account.id)) else: accounts = list(store.find(AccountView)) accounts = self._orderaccounts(accounts) for account in accounts: account.total = self._calculate_total(accounts, account) if self.create_mode and account.matches(till_id): account.selectable = False self.add_account(account.parent_id, account) selectable = not self.create_mode # Tabs cache requires unique ids self.append( None, Settable(description=_("Accounts Payable"), id=-1, parent=None, kind='payable', selectable=selectable, total=None)) self.append( None, Settable(description=_("Accounts Receivable"), id=-2, parent=None, kind='receivable', selectable=selectable, total=None)) self.flush()
def register_payment_methods(store): """Registers the payment methods and creates persistent domain classes associated with them. """ from stoqlib.domain.payment.method import PaymentMethod from stoqlib.domain.payment.operation import get_payment_operation_manager log.info("Registering payment operations") pom = get_payment_operation_manager() log.info("Creating domain objects for payment methods") account_id = sysparam.get_object_id('IMBALANCE_ACCOUNT') assert account_id for operation_name in pom.get_operation_names(): operation = pom.get(operation_name) pm = store.find(PaymentMethod, method_name=operation_name).one() if pm is None: pm = PaymentMethod(store=store, method_name=operation_name, destination_account_id=account_id, max_installments=operation.max_installments)
def create_sale(self, branch=None, client=None): from stoqlib.domain.sale import Sale from stoqlib.domain.till import Till till = Till.get_current(self.store) if till is None: till = self.create_till() till.open_till() salesperson = self.create_sales_person() group = self.create_payment_group() if client: group.payer = client.person sale = Sale(coupon_id=0, open_date=TransactionTimestamp(), salesperson=salesperson, branch=branch or get_current_branch(self.store), cfop_id=sysparam.get_object_id('DEFAULT_SALES_CFOP'), group=group, client=client, store=self.store) return sale
def insert_initial(self, store, edited_account=None): """ Insert accounts and parent accounts in a ObjectTree. :param store: a store :param edited_account: If not None, this is the account being edited. In this case, this acount (and its decendents) will not be shown in the account tree. """ till_id = sysparam.get_object_id('TILLS_ACCOUNT') if self.create_mode and edited_account: accounts = list(store.find(AccountView, AccountView.id != edited_account.id)) else: accounts = list(store.find(AccountView)) accounts = self._orderaccounts(accounts) for account in accounts: account.total = self._calculate_total(accounts, account) if self.create_mode and account.matches(till_id): account.selectable = False self.add_account(account.parent_id, account) selectable = not self.create_mode # Tabs cache requires unique ids self.append(None, Settable(description=_("Accounts Payable"), id=-1, parent=None, kind='payable', selectable=selectable, total=None)) self.append(None, Settable(description=_("Accounts Receivable"), id=-2, parent=None, kind='receivable', selectable=selectable, total=None)) self.flush()
def get_delivery_item(self): delivery_service_id = sysparam.get_object_id('DELIVERY_SERVICE') for item in self.get_items(): if item.sellable.id == delivery_service_id: return item return None