class Comment(dd.Model): allow_cascaded_delete = ['owner'] owner_type = dd.ForeignKey(ContentType) owner_id = models.PositiveIntegerField() owner = GenericForeignKey('owner_type', 'owner_id') text = models.CharField(max_length=200)
class Memo(dd.Model): owner_type = dd.ForeignKey(ContentType, blank=True, null=True) owner_id = models.PositiveIntegerField(blank=True, null=True) owner = GenericForeignKey('owner_type', 'owner_id') text = models.CharField(max_length=200) def __str__(self): return '%s object' % (self.__class__.__name__)
class Comment(dd.Model): allow_cascaded_delete = ['owner'] owner_type = dd.ForeignKey(ContentType) owner_id = models.PositiveIntegerField() owner = GenericForeignKey('owner_type', 'owner_id') text = models.CharField(max_length=200) def __str__(self): return '%s object' % (self.__class__.__name__)
class Item(dd.Model): class Meta: app_label = 'invoicing' abstract = dd.is_abstract_model(__name__, 'Item') verbose_name = _("Invoicing suggestion") verbose_name_plural = _("Invoicing suggestions") plan = dd.ForeignKey('invoicing.Plan', related_name="items") partner = dd.ForeignKey('contacts.Partner') generator_type = dd.ForeignKey(ContentType, editable=True, blank=True, null=True, verbose_name=format_lazy( u"{} {}", generator_label, _('(type)'))) generator_id = GenericForeignKeyIdField(generator_type, editable=True, blank=True, null=True, verbose_name=format_lazy( u"{} {}", generator_label, _('(object)'))) generator = GenericForeignKey('generator_type', 'generator_id', verbose_name=generator_label) # first_date = models.DateField(_("First date")) # last_date = models.DateField(_("Last date")) amount = dd.PriceField(_("Amount"), default=ZERO) # number_of_invoiceables = models.IntegerField(_("Number"), default=0) preview = models.TextField(_("Preview"), blank=True) selected = models.BooleanField(_("Selected"), default=True) invoice = dd.ForeignKey(dd.plugins.invoicing.voucher_model, verbose_name=_("Invoice"), null=True, blank=True, on_delete=models.SET_NULL) exec_item = ExecuteItem() @dd.displayfield(_("Invoice")) def invoice_button(self, ar): if ar is not None: if self.invoice_id: return self.invoice.obj2href(ar) ba = ar.actor.get_action_by_name('exec_item') if ar.actor.get_row_permission(self, ar, None, ba): return ar.action_button(ba, self) return '' def create_invoice(self, ar): if self.plan.area_id is None: raise Warning(_("No area specified")) if self.plan.area.journal is None: raise Warning( _("No journal configured for {}").format(self.plan.area)) invoice = self.plan.create_invoice(partner=self.partner, user=ar.get_user()) lng = invoice.get_print_language() items = [] max_date = self.plan.get_max_date() with translation.override(lng): if self.generator: generators = [self.generator] else: generators = [ ig for ig in self.plan.get_generators_for_plan(self.partner) if ig.allow_group_invoices() ] for ig in generators: info = ig.compute_invoicing_info(max_date) pt = ig.get_invoiceable_payment_term() if pt: invoice.payment_term = pt pt = ig.get_invoiceable_paper_type() if pt: invoice.paper_type = pt # for i in ig.get_invoice_items(info, ITEM_MODEL, ar): for i in ig.get_invoice_items(info, invoice, ar): # kwargs.update(voucher=invoice) # i = ITEM_MODEL(**kwargs) # if 'amount' in kwargs: # i.set_amount(ar, kwargs['amount']) # amount = kwargs.get('amount', ZERO) # if amount: # i.set_amount(ar, amount) items.append((ig, i)) if len(items) == 0: # neither invoice nor items are saved raise Warning(_("No invoiceables found for %s.") % self) # dd.logger.warning( # _("No invoiceables found for %s.") % self.partner) # return invoice.full_clean() invoice.save() for ig, i in items: # assign voucher after it has been saved i.voucher = invoice ig.setup_invoice_item(i) # if not i.title: # i.title = ig.get_invoiceable_title(invoice) # compute the sales_price and amounts, but don't change # title and description # title = i.title # i.product_changed() i.discount_changed() # i.title = title i.full_clean() i.save() self.invoice = invoice self.full_clean() self.save() invoice.compute_totals() invoice.full_clean() invoice.save() invoice.register(ar) return invoice def __str__(self): return "{0} {1}".format(self.plan, self.partner)
blank=True, null=True, verbose_name=format_lazy(u"{} {}", invoiceable_label, _('(type)')))) dd.inject_field( dd.plugins.invoicing.item_model, 'invoiceable_id', GenericForeignKeyIdField('invoiceable_type', blank=True, null=True, verbose_name=format_lazy(u"{} {}", invoiceable_label, _('(object)')))) dd.inject_field( dd.plugins.invoicing.item_model, 'invoiceable', GenericForeignKey('invoiceable_type', 'invoiceable_id', verbose_name=invoiceable_label)) # dd.inject_field( # dd.plugins.invoicing.item_model, # 'item_no', models.IntegerField(_("Iten no.")) # define a custom chooser because we want to see only invoiceable # models when manually selecting an invoiceable_type: @dd.chooser() def invoiceable_type_choices(cls): return ContentType.objects.get_for_models( *rt.models_by_base(InvoiceGenerator)).values()
class Memo(dd.Model): owner_type = dd.ForeignKey(ContentType, blank=True, null=True) owner_id = models.PositiveIntegerField(blank=True, null=True) owner = GenericForeignKey('owner_type', 'owner_id') text = models.CharField(max_length=200)
class Note(dd.Model): owner_type = dd.ForeignKey(ContentType) owner_id = models.PositiveIntegerField() owner = GenericForeignKey('owner_type', 'owner_id') text = models.CharField(max_length=200)