def create_receiving_order(self, station): notes = u"Created automatically with Stoq-Link" # TODO Eventually get this from the invoice data. cfop = sysparam.get_object(self.store, 'DEFAULT_RECEIVING_CFOP') receiving_invoice = ReceivingInvoice( store=self.store, freight_total=self.freight_cost, invoice_number=self.invoice_number, invoice_total=self.total_cost, supplier=self.purchase_order.supplier, branch=self.branch, responsible=self.user, station=station) receiving_order = ReceivingOrder(store=self.store, branch=self.branch, station=station, notes=notes, cfop=cfop, confirm_date=datetime.datetime.now(), status=u'closed', receiving_invoice=receiving_invoice) receiving_order.add_purchase(self.purchase_order) for item in self.purchase_order.get_items(): receiving_order.add_purchase_item(item=item) if self.freight_type == PurchaseOrder.FREIGHT_CIF: receiving_order.update_payments(create_freight_payment=True) receiving_invoice.freight_type = receiving_invoice.guess_freight_type() receiving_order.confirm(self.user) return receiving_order
def test_default_receiving_cfop(self): branch = self.create_branch() param = self.sparam.get_object(self.store, 'DEFAULT_RECEIVING_CFOP') person = Person(name=u'Craudinho', store=self.store) Individual(person=person, store=self.store) profile = UserProfile(name=u'profile', store=self.store) responsible = LoginUser(person=person, store=self.store, password=u'asdfgh', profile=profile, username=u'craudio') receiving_order = ReceivingOrder(responsible=responsible, branch=branch, store=self.store, invoice_number=876, supplier=None) param2 = self.sparam.get_object(self.store, 'DEFAULT_SALES_CFOP') receiving_order2 = ReceivingOrder(responsible=responsible, cfop=param2, branch=branch, store=self.store, invoice_number=1231, supplier=None) self.assertEqual(param, receiving_order.cfop) self.failIfEqual(param, receiving_order2.cfop)
def _create_receiving_order(self): supplier_id = self.purchases[0].supplier_id branch_id = self.purchases[0].branch_id # If the receiving is for another branch, we need a temporary identifier temporary_identifier = None if (api.sysparam.get_bool('SYNCHRONIZED_MODE') and api.get_current_branch(self.store).id != branch_id): temporary_identifier = ReceivingOrder.get_temporary_identifier( self.store) # 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 receiving_invoice = ReceivingInvoice(supplier=supplier_id, store=self.store, branch=branch_id, responsible=api.get_current_user( self.store)) self.wizard.model = self.model = ReceivingOrder( identifier=temporary_identifier, receiving_invoice=receiving_invoice, responsible=receiving_invoice.responsible, invoice_number=None, branch=branch_id, store=self.store) for row in self.purchases: self.model.add_purchase(row.purchase)
def create_receiving_order(self): from stoqlib.domain.receiving import ReceivingOrder receiving = ReceivingOrder(self.store, branch=self.branch) receiving.add_purchase(self) for item in self.get_items(): receiving.add_purchase_item(item, quantity=item.quantity, ipi_value=item.ipi_value) return receiving
def test_constructor(self): cfop = self.create_cfop_data() branch = self.create_branch() # When we don't provide a CFOP, the constructor should use the default # one order = ReceivingOrder(self.store, branch=branch) self.assertNotEqual(order.cfop, None) self.assertNotEqual(order.cfop, cfop) order = ReceivingOrder(self.store, cfop=cfop, branch=branch) self.assertEqual(order.cfop, cfop)
def create_receiving_order(self, purchase_order=None, branch=None, user=None): from stoqlib.domain.receiving import ReceivingOrder if purchase_order is None: purchase_order = self.create_purchase_order() cfop = self.create_cfop_data() cfop.code = u'1.102' receiving = ReceivingOrder(store=self.store, invoice_number=222, supplier=purchase_order.supplier, responsible=user or get_current_user(self.store), branch=branch or get_current_branch(self.store), cfop=cfop) receiving.add_purchase(purchase_order) return receiving
def _create_receiving_order(self): supplier_id = self.purchases[0].supplier_id branch_id = self.purchases[0].branch_id # If the receiving is for another branch, we need a temporary identifier temporary_identifier = None if (api.sysparam.get_bool('SYNCHRONIZED_MODE') and api.get_current_branch(self.store).id != branch_id): temporary_identifier = ReceivingOrder.get_temporary_identifier(self.store) # 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 receiving_invoice = ReceivingInvoice( supplier=supplier_id, store=self.store, branch=branch_id, responsible=api.get_current_user(self.store)) self.wizard.model = self.model = ReceivingOrder( identifier=temporary_identifier, receiving_invoice=receiving_invoice, responsible=receiving_invoice.responsible, invoice_number=None, branch=branch_id, store=self.store) for row in self.purchases: self.model.add_purchase(row.purchase)
def post_init(self): # A receiving model was created. We should remove it (and its items), # since after this step we can either receive the products now or # later, on the stock application. receiving_model = self.wizard.receiving_model if receiving_model: for item in receiving_model.get_items(): ReceivingOrderItem.delete(item.id, self.store) ReceivingOrder.delete(receiving_model.id, store=self.store) self.wizard.receiving_model = None self.salesperson_name.grab_focus() self._set_receival_date_suggestion() self.register_validate_function(self.wizard.refresh_next) self.force_validation()
def _create_receiving_order(self): self.model.set_consigned() receiving_model = ReceivingOrder( responsible=api.get_current_user(self.store), purchase=self.model, supplier=self.model.supplier, branch=self.model.branch, transporter=self.model.transporter, invoice_number=None, store=self.store) # Creates ReceivingOrderItem's for item in self.model.get_pending_items(): receiving_model.add_purchase_item(item) self.wizard.receiving_model = receiving_model
def _create_receiving_order(self): # since we will create a new receiving order, we should confirm the # purchase first. Note that the purchase may already be confirmed if self.model.status in [ PurchaseOrder.ORDER_PENDING, PurchaseOrder.ORDER_CONSIGNED ]: self.model.confirm(api.get_current_user(self.store)) temporary_identifier = None if self.wizard.is_for_another_branch(): temporary_identifier = ReceivingOrder.get_temporary_identifier( self.store) receiving_invoice = ReceivingInvoice( store=self.store, supplier=self.model.supplier, branch=self.model.branch, station=api.get_current_station(self.store), responsible=api.get_current_user(self.store)) receiving_model = ReceivingOrder( identifier=temporary_identifier, receiving_invoice=receiving_invoice, responsible=receiving_invoice.responsible, branch=self.model.branch, station=api.get_current_station(self.store), invoice_number=None, store=self.store) receiving_model.add_purchase(self.model) # Creates ReceivingOrderItem's for item in self.model.get_pending_items(): receiving_model.add_purchase_item(item) self.wizard.receiving_model = receiving_model
def _create_receiving_order(self): # since we will create a new receiving order, we should confirm the # purchase first. self.model.confirm() receiving_model = ReceivingOrder(responsible=api.get_current_user( self.store), purchase=self.model, supplier=self.model.supplier, branch=self.model.branch, transporter=self.model.transporter, invoice_number=None, store=self.store) # Creates ReceivingOrderItem's for item in self.model.get_pending_items(): receiving_model.add_purchase_item(item) self.wizard.receiving_model = receiving_model
def _create_receiving_order(self): # since we will create a new receiving order, we should confirm the # purchase first. self.model.confirm() receiving_model = ReceivingOrder( responsible=api.get_current_user(self.store), purchase=self.model, supplier=self.model.supplier, branch=self.model.branch, transporter=self.model.transporter, invoice_number=None, store=self.store) # Creates ReceivingOrderItem's for item in self.model.get_pending_items(): receiving_model.add_purchase_item(item) self.wizard.receiving_model = receiving_model
def _create_receiving_order(self): # since we will create a new receiving order, we should confirm the # purchase first. Note that the purchase may already be confirmed if self.model.status in [PurchaseOrder.ORDER_PENDING, PurchaseOrder.ORDER_CONSIGNED]: self.model.confirm() temporary_identifier = None if self.wizard.is_for_another_branch(): temporary_identifier = ReceivingOrder.get_temporary_identifier(self.store) receiving_invoice = ReceivingInvoice( store=self.store, supplier=self.model.supplier, branch=self.model.branch, responsible=api.get_current_user(self.store)) receiving_model = ReceivingOrder( identifier=temporary_identifier, receiving_invoice=receiving_invoice, responsible=receiving_invoice.responsible, branch=self.model.branch, invoice_number=None, store=self.store) receiving_model.add_purchase(self.model) # Creates ReceivingOrderItem's for item in self.model.get_pending_items(): receiving_model.add_purchase_item(item) self.wizard.receiving_model = receiving_model
def create_receiving_order(self, purchase_order=None, branch=None, user=None): from stoqlib.domain.receiving import ReceivingOrder if purchase_order is None: purchase_order = self.create_purchase_order() cfop = self.create_cfop_data() cfop.code = u'1.102' return ReceivingOrder(store=self.store, invoice_number=222, supplier=purchase_order.supplier, responsible=user or get_current_user(self.store), purchase=purchase_order, branch=branch or get_current_branch(self.store), cfop=cfop)
def create_receiving_order(self): from stoqlib.domain.receiving import ReceivingOrder receiving = ReceivingOrder(self.store, branch=self.branch) receiving.add_purchase(self) for item in self.get_items(): receiving.add_purchase_item(item, quantity=item.quantity) return receiving
def create_receiving_order(self, station: BranchStation): from stoqlib.domain.receiving import ReceivingOrder receiving = ReceivingOrder(self.store, branch=self.branch, station=station) receiving.add_purchase(self) for item in self.get_items(): receiving.add_purchase_item(item, quantity=item.quantity, ipi_value=item.ipi_value) return receiving
def _create_receiving_order(self): # We only let the user get this far if the purchases select are for the # same branch and supplier supplier_id = self.purchases[0].supplier_id branch_id = self.purchases[0].branch_id # 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 self.wizard.model = self.model = ReceivingOrder( responsible=api.get_current_user(self.store), supplier=supplier_id, invoice_number=None, branch=branch_id, store=self.store) for row in self.purchases: self.model.add_purchase(row.purchase)
def next_step(self): self.search.save_columns() selected = self.search.results.get_selected() 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=api.get_current_user(self.store), supplier=purchase.supplier, invoice_number=None, branch=purchase.branch, purchase=purchase, store=self.store) # Remove all the items added previously, used if we hit back # at any point in the wizard. if self.model.purchase != purchase: self.model.remove_items() # This forces ReceivingOrderProductStep to create a new model self._next_step = None if selected: self.model.purchase = purchase self.model.branch = purchase.branch self.model.supplier = purchase.supplier self.model.transporter = purchase.transporter else: self.model.purchase = None # FIXME: Improve the infrastructure to avoid this local caching of # Wizard steps. if not self._next_step: # Remove all the items added previously, used if we hit back # at any point in the wizard. self._next_step = ReceivingOrderItemStep(self.store, self.wizard, self.model, self) return self._next_step
def _create_receiving_order(self): # since we will create a new receiving order, we should confirm the # purchase first. Note that the purchase may already be confirmed if self.model.status in [PurchaseOrder.ORDER_PENDING, PurchaseOrder.ORDER_CONSIGNED]: self.model.confirm() receiving_model = ReceivingOrder( responsible=api.get_current_user(self.store), supplier=self.model.supplier, branch=self.model.branch, transporter=self.model.transporter, invoice_number=None, store=self.store) receiving_model.add_purchase(self.model) # Creates ReceivingOrderItem's for item in self.model.get_pending_items(): receiving_model.add_purchase_item(item) self.wizard.receiving_model = receiving_model
def _create_receiving_order(self): self.model.set_consigned(api.get_current_user(self.store)) receiving_invoice = ReceivingInvoice( supplier=self.model.supplier, store=self.store, branch=self.model.branch, station=api.get_current_station(self.store), responsible=api.get_current_user(self.store)) receiving_model = ReceivingOrder( responsible=receiving_invoice.responsible, branch=self.model.branch, station=api.get_current_station(self.store), invoice_number=None, receiving_invoice=receiving_invoice, store=self.store) receiving_model.add_purchase(self.model) # Creates ReceivingOrderItem's for item in self.model.get_pending_items(): receiving_model.add_purchase_item(item) self.wizard.receiving_model = receiving_model
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()
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 person = store.find(Person, name=data.user_name).one() if person is None or person.login_user is None: raise ValueError(u"%s is not a valid user" % ( data.user_name, )) login_user = person.login_user group = PaymentGroup(store=store) purchase = PurchaseOrder(store=store, status=PurchaseOrder.ORDER_PENDING, 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() 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()