def edit_form(self, obj=None): form = super(DirectPurchaseOrderAdmin, self).edit_form(obj) supplier_id = obj.transient_supplier.id # Set query_factory for newly added line form.lines.form.product.kwargs['query_factory'] = partial( Product.supplier_filter, supplier_id) if not security_util.user_has_role('purchase_price_view'): form_util.del_form_field(self, form, 'goods_amount') form_util.del_form_field(self, form, 'total_amount') form_util.del_inline_form_field(form.lines.form, form.lines.entries, 'unit_price') form_util.del_inline_form_field(form.lines.form, form.lines.entries, 'total_amount') # Set option list of status available if obj.status.code in [ const.PO_RECEIVED_STATUS_KEY, const.PO_PART_RECEIVED_STATUS_KEY, const.PO_PART_RECEIVED_STATUS_KEY, const.PO_ISSUED_STATUS_KEY, const.PO_DRAFT_STATUS_KEY ]: form.status.query = [ EnumValues.get(obj.status.code), ] if obj.status.code == const.PO_DRAFT_STATUS_KEY: form.status.query.append(EnumValues.get( const.PO_ISSUED_STATUS_KEY)) # Set product query option for old lines(forbid to change product for # existing line) line_entries = form.lines.entries products = Product.supplier_filter(supplier_id).all() for sub_line in line_entries: sub_line.form.product.query = products return form
def edit_form(self, obj=None): form = super(DirectPurchaseOrderAdmin, self).edit_form(obj) supplier_id = obj.transient_supplier.id # Set query_factory for newly added line form.lines.form.product.kwargs['query_factory'] = partial( Product.supplier_filter, supplier_id) if not security_util.user_has_role('purchase_price_view'): form_util.del_form_field(self, form, 'goods_amount') form_util.del_form_field(self, form, 'total_amount') form_util.del_inline_form_field(form.lines.form, form.lines.entries, 'unit_price') form_util.del_inline_form_field(form.lines.form, form.lines.entries, 'total_amount') # Set option list of status available if obj.status.code in [const.PO_RECEIVED_STATUS_KEY, const.PO_PART_RECEIVED_STATUS_KEY, const.PO_PART_RECEIVED_STATUS_KEY, const.PO_ISSUED_STATUS_KEY, const.PO_DRAFT_STATUS_KEY]: form.status.query = [EnumValues.get(obj.status.code), ] if obj.status.code == const.PO_DRAFT_STATUS_KEY: form.status.query.append( EnumValues.get(const.PO_ISSUED_STATUS_KEY)) # Set product query option for old lines(forbid to change product for # existing line) line_entries = form.lines.entries products = Product.supplier_filter(supplier_id).all() for sub_line in line_entries: sub_line.form.product.query = products return form
def edit_form(self, obj=None): form = super(FranchisePurchaseOrderAdmin, self).edit_form(obj) # Set query_factory for newly added line parent_org_id = obj.to_organization.id # If we uncomment follow line to limit the query to current organization # The AJAX look up fails. # form.lines.form.product.kwargs['query_factory'] = partial( # Product.organization_filter, parent_org_id) if not security_util.user_has_role('purchase_price_view'): form_util.del_form_field(self, form, 'goods_amount') form_util.del_form_field(self, form, 'total_amount') form_util.del_inline_form_field(form.lines.form, form.lines.entries, 'total_amount') form_util.del_inline_form_field(form.lines.form, form.lines.entries, 'unit_price') # Set option list of status available if obj.status.code in [ const.PO_RECEIVED_STATUS_KEY, const.PO_PART_RECEIVED_STATUS_KEY, const.PO_PART_RECEIVED_STATUS_KEY, const.PO_ISSUED_STATUS_KEY, const.PO_DRAFT_STATUS_KEY ]: form.status.query = [ EnumValues.get(obj.status.code), ] if obj.status.code == const.PO_DRAFT_STATUS_KEY: form.status.query.append(EnumValues.get( const.PO_ISSUED_STATUS_KEY)) # Set product query option for old lines(forbid to change product for # existing line) line_entries = form.lines.entries products = Product.organization_filter(parent_org_id).all() for sub_line in line_entries: sub_line.form.product.query = products return form
def line_fields(self): if not security_util.user_has_role('purchase_price_view'): return [product_field, quantity_field] else: return [ product_field, quantity_field, price_field, total_amount_field ]
def edit_form(self, obj=None): form = super(FranchisePurchaseOrderAdmin, self).edit_form(obj) # Set query_factory for newly added line parent_org_id = obj.to_organization.id # If we uncomment follow line to limit the query to current organization # The AJAX look up fails. # form.lines.form.product.kwargs['query_factory'] = partial( # Product.organization_filter, parent_org_id) if not security_util.user_has_role('purchase_price_view'): form_util.del_form_field(self, form, 'goods_amount') form_util.del_form_field(self, form, 'total_amount') form_util.del_inline_form_field(form.lines.form, form.lines.entries, 'total_amount') form_util.del_inline_form_field(form.lines.form, form.lines.entries, 'unit_price') # Set option list of status available if obj.status.code in [const.PO_RECEIVED_STATUS_KEY, const.PO_PART_RECEIVED_STATUS_KEY, const.PO_PART_RECEIVED_STATUS_KEY, const.PO_ISSUED_STATUS_KEY, const.PO_DRAFT_STATUS_KEY]: form.status.query = [EnumValues.get(obj.status.code), ] if obj.status.code == const.PO_DRAFT_STATUS_KEY: form.status.query.append( EnumValues.get(const.PO_ISSUED_STATUS_KEY)) # Set product query option for old lines(forbid to change product for # existing line) line_entries = form.lines.entries products = Product.organization_filter(parent_org_id).all() for sub_line in line_entries: sub_line.form.product.query = products return form
def line_fields(self): if not security_util.user_has_role('purchase_price_view'): return [type_field, date_field, product_field, quantity_field, saleable_quantity_field, remark_field] return [type_field, date_field, product_field, price_field, quantity_field, total_amount_field, saleable_quantity_field, remark_field]
def line_fields(self): # TODO.xqliu Move the judgetment stragegy to a separate method to avoid repeat myself!!! if not security_util.user_has_role('purchase_price_view'): return [product_field, quantity_field] return [ product_field, price_field, quantity_field, price_field, total_amount_field ]
def line_fields(self): if not security_util.user_has_role('purchase_price_view'): return [product_field, quantity_field, remark_field] else: return [ product_field, quantity_field, unit_price_field, total_amount_field, remark_field ]
def edit_form(self, obj=None): from psi.app.models import ProductCategory, Supplier form = super(ProductAdmin, self).edit_form(obj) form.images_placeholder.set_object_type(ProductImage) form_util.filter_by_organization(form.category, ProductCategory) form_util.filter_by_organization(form.supplier, Supplier) if not security_util.user_has_role('purchase_price_view'): form_util.del_form_field(self, form, 'purchase_price') return form
def on_model_change(self, form, model, is_created): super(BasePurchaseOrderAdmin, self).on_model_change(form, model, is_created) if not security_util.user_has_role('purchase_price_view'): for l in model.lines: l.unit_price = l.product.purchase_price DeleteValidator.validate_status_for_change( model, const.PO_RECEIVED_STATUS_KEY, gettext('Purchase order can not be update nor delete on received status') ) if is_created: model.type = EnumValues.get(self.type_code) PurchaseOrderService.create_expense_receiving(model)
def on_model_change(self, form, model, is_created): super(BasePurchaseOrderAdmin, self).on_model_change( form, model, is_created) if not security_util.user_has_role('purchase_price_view'): for l in model.lines: l.unit_price = l.product.purchase_price DeleteValidator.validate_status_for_change( model, const.PO_RECEIVED_STATUS_KEY, gettext( 'Purchase order can not be update nor delete on received status' )) if is_created: model.type = EnumValues.get(self.type_code) PurchaseOrderService.create_expense_receiving(model)
def edit_form(self, obj=None): from psi.app.models import PurchaseOrderLine, EnumValues form = super(ReceivingAdmin, self).edit_form(obj) po_id = obj.transient_po.id # Set query_factory for newly added line form.lines.form.purchase_order_line.kwargs['query_factory'] = partial(PurchaseOrderLine.header_filter, po_id) if obj is not None and obj.status is not None and obj.status.code == const.RECEIVING_COMPLETE_STATUS_KEY: form.status.query = [EnumValues.get(const.RECEIVING_COMPLETE_STATUS_KEY), ] # Set query option for old lines line_entries = form.lines.entries po_lines = PurchaseOrderLine.header_filter(po_id).all() if not security_util.user_has_role('purchase_price_view'): form_util.del_form_field(self, form, 'total_amount') form_util.del_inline_form_field(form.lines.form, form.lines.entries, 'transient_price') form_util.del_inline_form_field(form.lines.form, form.lines.entries, 'total_amount') for sub_line in line_entries: sub_line.form.purchase_order_line.query = po_lines return form
def edit_form(self, obj=None): from psi.app.models import PurchaseOrderLine, EnumValues form = super(ReceivingAdmin, self).edit_form(obj) po_id = obj.transient_po.id # Set query_factory for newly added line form.lines.form.purchase_order_line.kwargs['query_factory'] = partial( PurchaseOrderLine.header_filter, po_id) if obj is not None and obj.status is not None and obj.status.code == const.RECEIVING_COMPLETE_STATUS_KEY: form.status.query = [ EnumValues.get(const.RECEIVING_COMPLETE_STATUS_KEY), ] # Set query option for old lines line_entries = form.lines.entries po_lines = PurchaseOrderLine.header_filter(po_id).all() if not security_util.user_has_role('purchase_price_view'): form_util.del_form_field(self, form, 'total_amount') form_util.del_inline_form_field(form.lines.form, form.lines.entries, 'transient_price') form_util.del_inline_form_field(form.lines.form, form.lines.entries, 'total_amount') for sub_line in line_entries: sub_line.form.purchase_order_line.query = po_lines return form
def column_details_list(self): if not security_util.user_has_role('purchase_price_view'): return ('id', 'sales_order', 'status', 'date', 'remark', 'lines', 'inventory_transaction') return ('id', 'sales_order', 'status', 'date', 'total_amount', 'remark', 'lines', 'inventory_transaction')
def is_accessible(self): return user_has_role('import_store_data')
def column_details_list(self): if not security_util.user_has_role('purchase_price_view'): return ('id', 'sales_order', 'status', 'date', 'remark', 'lines', 'inventory_transaction') return ('id', 'sales_order', 'status', 'date', 'total_amount', 'remark', 'lines', 'inventory_transaction')
def line_fields(self): # TODO.xqliu Move the judgetment stragegy to a separate method to avoid repeat myself!!! if not security_util.user_has_role('purchase_price_view'): return [product_field, quantity_field] return [product_field, price_field, quantity_field, price_field, total_amount_field]