def create_gift_cards(self): ''' Create the actual gift card for this line ''' GiftCard = Pool().get('gift_card.gift_card') if not self.is_gift_card: # Not a gift card line return None product = self.product if product.allow_open_amount and not (product.gc_min <= self.unit_price <= product.gc_max): self.raise_user_error("amounts_out_of_range", (self.sale.currency.code, product.gc_min, self.sale.currency.code, product.gc_max)) # XXX: Do not consider cancelled ones in the gift cards. # card could have been cancelled for reasons like wrong message ? quantity_created = len(self.gift_cards) if self.sale.gift_card_method == 'order': quantity = self.quantity - quantity_created else: # On invoice paid quantity_paid = 0 for invoice_line in self.invoice_lines: if invoice_line.invoice.state == 'paid': invoice_line.quantity quantity_paid += invoice_line.quantity # Remove already created gift cards quantity = quantity_paid - quantity_created if not quantity > 0: # No more gift cards to create return gift_cards = GiftCard.create([{ 'amount': self.unit_price, 'sale_line': self.id, 'message': self.message, 'recipient_email': self.recipient_email, 'recipient_name': self.recipient_name, 'origin': '%s,%d' % (self.sale.__name__, self.sale.id), } for each in range(0, int(quantity))]) GiftCard.activate(gift_cards) return gift_cards
def create_gift_cards(self): ''' Create the actual gift card for this line ''' GiftCard = Pool().get('gift_card.gift_card') if not self.is_gift_card: # Not a gift card line return None product = self.product if product.allow_open_amount and not ( product.gc_min <= self.unit_price <= product.gc_max ): self.raise_user_error( "amounts_out_of_range", ( self.sale.currency.code, product.gc_min, self.sale.currency.code, product.gc_max ) ) # XXX: Do not consider cancelled ones in the gift cards. # card could have been cancelled for reasons like wrong message ? quantity_created = len(self.gift_cards) if self.sale.gift_card_method == 'order': quantity = self.quantity - quantity_created else: # On invoice paid quantity_paid = 0 for invoice_line in self.invoice_lines: if invoice_line.invoice.state == 'paid': invoice_line.quantity quantity_paid += invoice_line.quantity # Remove already created gift cards quantity = quantity_paid - quantity_created if not quantity > 0: # No more gift cards to create return gift_cards = GiftCard.create([{ 'amount': self.unit_price, 'sale_line': self.id, 'message': self.message, 'recipient_email': self.recipient_email, 'recipient_name': self.recipient_name, 'origin': '%s,%d' % (self.sale.__name__, self.sale.id), } for each in range(0, int(quantity))]) GiftCard.activate(gift_cards) return gift_cards
def create_gift_cards(self): ''' Create the actual gift card for this line ''' GiftCard = Pool().get('gift_card.gift_card') if not self.is_gift_card: # Not a gift card line return None if self.gift_cards: # pragma: no cover # Cards already created return None product = self.product if product.allow_open_amount and not ( product.gc_min <= self.unit_price <= product.gc_max ): self.raise_user_error( "amounts_out_of_range", ( self.sale.currency.code, product.gc_min, self.sale.currency.code, product.gc_max ) ) gift_cards = GiftCard.create([{ 'amount': self.unit_price, 'sale_line': self.id, 'message': self.message, 'recipient_email': self.recipient_email, 'recipient_name': self.recipient_name, 'origin': '%s,%d' % (self.sale.__name__, self.sale.id), } for each in range(0, int(self.quantity))]) # TODO: have option of creating card after invoice is paid ? GiftCard.activate(gift_cards) return gift_cards