def test_create(self): # Allow creating purchases in the past. sysparam.set_bool(self.store, 'ALLOW_OUTDATED_OPERATIONS', True) with self.sysparam(MANDATORY_CHECK_NUMBER=True): self.wizard = PurchaseWizard(self.store) purchase_branch = self.create_branch() purchase_order = PurchaseOrder(branch=purchase_branch, station=self.current_station, store=self.store) sellable = self.create_sellable() purchase_order.add_item(sellable=sellable) self.wizard.model.identifier = 12345 self.wizard.model.open_date = localdate(2010, 1, 3).date() self._check_start_step('wizard-purchase-start-step') self._check_item_step('wizard-purchase-item-step') payment_step = self.wizard.get_current_step() payment_step.slave.bank_first_check_number.set_text('12') self._check_payment_step('wizard-purchase-payment-step') purchase = self.wizard.model models = [purchase] models.extend(purchase.get_items()) models.extend(purchase.payments) models.append(purchase.group) self.check_wizard(self.wizard, 'wizard-purchase-finish-step', models=models) self.click(self.wizard.next_button)
def create_purchase(self, supplier, work_order_item, is_freebie): """Create a purchase :param supplier: the |supplier| of that purchase :param work_order_item: The work order item that a purchase is being created for. :param is_freebie: indicates if the item is a freebie """ sellable = work_order_item.sellable store = self.work_order.store purchase = PurchaseOrder(store=store, status=PurchaseOrder.ORDER_PENDING, supplier=supplier, responsible=api.get_current_user(store), branch=api.get_current_branch(store), work_order=self.work_order) if is_freebie: purchase.notes = _('The product %s is a freebie') % sellable.description # FIXME We may want the cost 0, but as it is we wont be able to # receive this purchase without changing the receiving. We must # evaluate the consequences of changing the receiving a little bit # further in order to change that behavior. cost = decimal.Decimal('0.01') else: cost = sellable.cost # Add the sellable to the purchase purchase_item = purchase.add_item(sellable, quantity=work_order_item.quantity, cost=cost) work_order_item.purchase_item = purchase_item purchase.confirm() return purchase
def test_create(self): # Allow creating purchases in the past. sysparam(self.store).update_parameter(u"ALLOW_OUTDATED_OPERATIONS", u"1") self.wizard = PurchaseWizard(self.store) purchase_branch = self.create_branch() purchase_order = PurchaseOrder(branch=purchase_branch) sellable = self.create_sellable() purchase_order.add_item(sellable=sellable) self.wizard.model.identifier = 12345 self.wizard.model.open_date = localdate(2010, 1, 3).date() self._check_start_step('wizard-purchase-start-step') self._check_item_step('wizard-purchase-item-step') self._check_payment_step('wizard-purchase-payment-step') purchase = self.wizard.model models = [purchase] models.extend(purchase.get_items()) models.extend(purchase.payments) models.append(purchase.group) self.check_wizard(self.wizard, 'wizard-purchase-finish-step', models=models) self.click(self.wizard.next_button)
def create_purchase_order(self, supplier=None, branch=None): from stoqlib.domain.purchase import PurchaseOrder group = self.create_payment_group() return PurchaseOrder(supplier=supplier or self.create_supplier(), branch=branch or self.create_branch(), group=group, responsible=get_current_user(self.store), store=self.store)
def _create_model(self, store): supplier = sysparam(store).SUGGESTED_SUPPLIER branch = api.get_current_branch(store) status = PurchaseOrder.ORDER_QUOTING group = PaymentGroup(store=store) return PurchaseOrder(supplier=supplier, 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_purchase_order(self, store, supplier, items): order = PurchaseOrder(supplier=store.fetch(supplier), branch=api.get_current_branch(store), status=PurchaseOrder.ORDER_QUOTING, expected_receival_date=None, responsible=api.get_current_user(store), group=PaymentGroup(store=store), store=store) for sellable, quantity in items: order.add_item(store.fetch(sellable), quantity) return order
def _create_and_confirm_purchase_order(self, identifier, payment_group, notes, station, responsible): self.purchase_order = PurchaseOrder( store=self.store, identifier=identifier, branch=self.branch, status=PurchaseOrder.ORDER_PENDING, open_date=localnow(), notes=notes, freight_type=self.freight_type, expected_freight=self.freight_cost, supplier=self.nfe_supplier.supplier, group=payment_group, station=station) self._add_purchase_order_item() self.purchase_order.confirm(responsible=responsible)
def process_one(self, data, fields, store): person = store.find(Person, name=data.supplier_name).one() if person is None or person.supplier is None: raise ValueError(u"%s is not a valid supplier" % (data.supplier_name, )) supplier = person.supplier person = store.find(Person, name=data.transporter_name).one() if person is None or person.transporter is None: raise ValueError(u"%s is not a valid transporter" % (data.transporter_name, )) transporter = person.transporter 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 login_user = store.find(LoginUser, username=u'admin').one() group = PaymentGroup(store=store) purchase = PurchaseOrder(store=store, status=PurchaseOrder.ORDER_PENDING, open_date=self.parse_date(data.due_date), supplier=supplier, transporter=transporter, group=group, responsible=get_current_user(store), branch=branch) for sellable in self.parse_multi(Sellable, data.sellable_list, store): if not sellable.product: continue PurchaseItem(store=store, quantity=int(data.quantity), base_cost=sellable.cost, sellable=sellable, order=purchase) method = PaymentMethod.get_by_name(store, data.payment_method) method.create_payment(Payment.TYPE_OUT, purchase.group, branch, purchase.purchase_total, self.parse_date(data.due_date)) purchase.confirm() for payment in purchase.payments: payment.open_date = purchase.open_date receiving_order = ReceivingOrder(responsible=login_user, supplier=supplier, invoice_number=int(data.invoice), transporter=transporter, branch=branch, store=store) receiving_order.add_purchase(purchase) for purchase_item in purchase.get_items(): ReceivingOrderItem(store=store, cost=purchase_item.sellable.cost, sellable=purchase_item.sellable, quantity=int(data.quantity), purchase_item=purchase_item, receiving_order=receiving_order) receiving_order.confirm()