def all_apps_ready(self): from creme import billing self.CreditNote = billing.get_credit_note_model() self.Invoice = billing.get_invoice_model() self.Quote = billing.get_quote_model() self.SalesOrder = billing.get_sales_order_model() self.TemplateBase = billing.get_template_base_model() self.ProductLine = billing.get_product_line_model() self.ServiceLine = billing.get_service_line_model() super().all_apps_ready() self.register_billing_algorithm() self.register_billing_lines() from . import signals
def test_populate(self): # self.assertEqual(REL_SUB_SOLD, REL_SUB_SOLD_BY) # self.assertEqual(REL_OBJ_SOLD, REL_OBJ_SOLD_BY) sold = self.get_relationtype_or_fail( REL_SUB_SOLD, [Contact, Organisation], [Product, Service], ) self.assertEqual(REL_OBJ_SOLD, sold.symmetric_type_id) complete_goal = self.get_object_or_fail(RelationType, id=REL_SUB_COMPLETE_GOAL) self.assertEqual(REL_OBJ_COMPLETE_GOAL, complete_goal.symmetric_type_id) self.assertEqual( [Act], [ct.model_class() for ct in complete_goal.object_ctypes.all()]) subject_models = { ct.model_class() for ct in complete_goal.subject_ctypes.all() } self.assertIn(Contact, subject_models) self.assertIn(Organisation, subject_models) if apps.is_installed('creme.billing'): from creme import billing self.assertIn(billing.get_invoice_model(), subject_models) self.assertIn(billing.get_quote_model(), subject_models) self.assertIn(billing.get_sales_order_model(), subject_models) self.assertNotIn(billing.get_product_line_model(), subject_models) self.assertNotIn(billing.get_service_line_model(), subject_models) self.assertNotIn(billing.get_template_base_model(), subject_models) self.get_propertytype_or_fail(PROP_IS_A_SALESMAN, [Contact]) self.assertEqual(3, ActType.objects.count()) self.get_object_or_fail(MarketSegment, property_type=None)
from creme.billing.constants import REL_SUB_BILL_ISSUED, REL_SUB_BILL_RECEIVED from creme.creme_core.http import is_ajax from creme.creme_core.models import Relation, SettingValue, Vat from creme.creme_core.views.generic import base from creme.creme_core.views.relation import RelationsObjectsSelectionPopup from creme.persons import workflow from creme.products import get_product_model from .. import constants, get_opportunity_model from ..setting_keys import emitter_constraint_key, target_constraint_key Invoice = billing.get_invoice_model() Quote = billing.get_quote_model() SalesOrder = billing.get_sales_order_model() ProductLine = billing.get_product_line_model() ServiceLine = billing.get_service_line_model() Opportunity = get_opportunity_model() class CurrentQuoteSetting(base.CheckedView): permissions = 'opportunities' action_url_kwarg = 'action' opp_id_url_kwarg = 'opp_id' quote_id_url_kwarg = 'quote_id' rtype_id = constants.REL_SUB_CURRENT_DOC def post(self, request, *args, **kwargs): user = request.user action = self.kwargs[self.action_url_kwarg]
class ServiceLinesEntry(menu.ListviewEntry): id = 'billing-service_lines' model = billing.get_service_line_model()
def export_as_pdf(request, base_id): entity = get_object_or_404(CremeEntity, pk=base_id).get_real_entity() has_perm = request.user.has_perm_to_view_or_die has_perm(entity) template_path = TEMPLATE_PATHS.get(entity.__class__) if template_path is None: raise ConflictError('This type of entity cannot be exported as pdf') source = entity.get_source().get_real_entity() has_perm(source) target = entity.get_target().get_real_entity() has_perm(target) document_name = str(entity._meta.verbose_name) template = loader.get_template(template_path) context = { 'plines': entity.get_lines(billing.get_product_line_model()), 'slines': entity.get_lines(billing.get_service_line_model()), 'source': source, 'target': target, 'object': entity, 'document_name': document_name, } basename = secure_filename('{}_{}'.format(document_name, entity.id)) tmp_dir_path = mkdtemp(prefix='creme_billing_latex') latex_file_path = path.join(tmp_dir_path, '{}.tex'.format(basename)) # NB: we precise the encoding or it oddly crashes on some systems... with open(latex_file_path, 'w', encoding='utf-8') as f: f.write(smart_str(template.render(context))) # NB: return code seems always 1 even when there is no error... subprocess.call([ 'pdflatex', '-interaction=batchmode', '-output-directory', tmp_dir_path, latex_file_path, ]) pdf_basename = '{}.pdf'.format(basename) temp_pdf_file_path = path.join(tmp_dir_path, pdf_basename) if not path.exists(temp_pdf_file_path): logger.critical( 'It seems the PDF generation has failed. ' 'The temporary directory has not been removed, ' 'so you can inspect the *.log file in "%s"', tmp_dir_path) # TODO: use a better exception class ? raise ConflictError( _('The generation of the PDF file has failed ; please contact your administrator.' )) final_path = FileCreator( dir_path=path.join(settings.MEDIA_ROOT, 'upload', 'billing'), name=pdf_basename, ).create() copy(temp_pdf_file_path, final_path) rmtree(tmp_dir_path) fileref = FileRef.objects.create( # user=request.user, TODO filedata='upload/billing/' + path.basename(final_path), basename=pdf_basename, ) return HttpResponseRedirect( reverse( 'creme_core__dl_file', args=(fileref.filedata, ), ))